Class: Preflight::Rules::MatchInfoEntries

Inherits:
Object
  • Object
show all
Defined in:
lib/preflight/rules/match_info_entries.rb

Instance Method Summary collapse

Constructor Details

#initialize(matches = {}) ⇒ MatchInfoEntries

Returns a new instance of MatchInfoEntries.



7
8
9
# File 'lib/preflight/rules/match_info_entries.rb', line 7

def initialize(matches = {})
  @matches = matches
end

Instance Method Details

#messages(ohash) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/preflight/rules/match_info_entries.rb', line 11

def messages(ohash)
  array = []
  info = ohash.object(ohash.trailer[:Info])
  @matches.each do |key, regexp|
    if !info.has_key?(key)
      array << "Info dict missing required key #{key}"
    elsif !info[key].to_s.match(regexp)
      array << "value of Info entry #{key} doesn't match (#{info[key]} != #{regexp})"
    end
  end
  array
end