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
12
13
14
15
16
17
18
19
20
21
# 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(
        name: prefix['name'],
        openapi2_json_path: prefix['openapi2_json_path'],
        openapi3_yaml_path: prefix['openapi3_yaml_path'],
        drafter_yaml_path: prefix['drafter_yaml_path'],
        tomogram_json_path: prefix['tomogram_json_path'],
        crafter_yaml_path: prefix['crafter_yaml_path'],
        skip: prefix['skip']
      )
    )
  end
end

Instance Method Details

#cram_into_the_appropriate_prefix(test) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/fitting/report/prefixes.rb', line 33

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

#join(tests) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/fitting/report/prefixes.rb', line 42

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

#there_a_suitable_prefix?(test_path) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
# File 'lib/fitting/report/prefixes.rb', line 23

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

  false
end

#to_aObject



51
52
53
# File 'lib/fitting/report/prefixes.rb', line 51

def to_a
  @prefixes
end