Class: Fitting::Report::Prefixes

Inherits:
Object
  • Object
show all
Defined in:
lib/fitting/report/prefixes.rb

Instance Method Summary collapse

Constructor Details

#initialize(config_path) ⇒ Prefixes

Returns a new instance of Prefixes.



6
7
8
9
10
11
# File 'lib/fitting/report/prefixes.rb', line 6

def initialize(config_path)
  @prefixes = []
  YAML.safe_load(File.read(config_path))['prefixes'].map do |prefix|
    @prefixes.push(Fitting::Report::Prefix.new(prefix['name'], prefix['tomogram_json_path'], prefix['skip']))
  end
end

Instance Method Details

#cram_into_the_appropriate_prefix(test) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/fitting/report/prefixes.rb', line 21

def cram_into_the_appropriate_prefix(test)
  @prefixes.map do |prefix|
    if test.path[0..prefix.name.size - 1] == prefix.name
      prefix.add_test(test)
      return
    end
  end
end

#is_there_a_suitable_prefix?(test_path) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
# File 'lib/fitting/report/prefixes.rb', line 13

def is_there_a_suitable_prefix?(test_path)
  @prefixes.map do |prefix|
    return true if test_path[0..prefix.name.size - 1] == prefix.name
  end

  false
end

#join(tests) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/fitting/report/prefixes.rb', line 30

def join(tests)
  tests.to_a.map do |test|
    if is_there_a_suitable_prefix?(test.path)
      cram_into_the_appropriate_prefix(test)
      test.mark_prefix
    end
  end
end

#to_aObject



39
40
41
# File 'lib/fitting/report/prefixes.rb', line 39

def to_a
  @prefixes
end