@@ -11,7 +11,6 @@ class Trial
1111 attr_reader :file_name , :parser , :user , :device , :analyzer
1212 attr_reader :user_params , :device_params
1313
14- # TODO: Set user, device, parser, analyzer here?
1514 def initialize ( file_name = nil , input_data = nil , user_params = nil , device_params = nil )
1615 if file_name
1716 @file_name = file_name
@@ -28,8 +27,7 @@ def initialize(file_name = nil, input_data = nil, user_params = nil, device_para
2827 "#{ device . trial . to_s . gsub ( /\s +/ , '' ) } -" +
2928 "#{ device . method } -#{ parser . format [ 0 ] } .txt"
3029 else
31- # TODO: Blow up and test
32- raise 'TODO: Blow up and tesr'
30+ raise 'File name or input data must be passed in.'
3331 end
3432 end
3533
@@ -50,14 +48,25 @@ def self.create(input_data, user_params, device_params)
5048 trial
5149 end
5250
53- # -- Instance Methods -----------------------------------------------------
51+ # TODO: Make sure to explain this part
52+ def self . find_matching_filtered_data ( trial )
53+ files = Dir . glob ( File . join ( 'public/uploads' , "*" ) )
54+ files . delete ( trial . file_name )
55+
56+ match = files . select { |f | trial . file_name == f . gsub ( '-s.' , '-c.' ) } . first
57+ match ||= files . select { |f | trial . file_name == f . gsub ( '-c.' , '-s.' ) } . first
5458
55- def data
56- @data ||= File . read ( file_name )
59+ match_filtered_data = if match
60+ parser = Parser . new ( File . read ( match ) )
61+ parser . filtered_data
62+ end
63+ match_filtered_data
5764 end
5865
66+ # -- Instance Methods -----------------------------------------------------
67+
5968 def parser
60- @parser ||= Parser . new ( data )
69+ @parser ||= Parser . new ( File . read ( file_name ) )
6170 end
6271
6372 def user
0 commit comments