Class: MetatagCop::Cops::Cop

Inherits:
Object
  • Object
show all
Defined in:
lib/metatag_cop/cops/cop.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(records) ⇒ Cop

Returns a new instance of Cop.



9
10
11
# File 'lib/metatag_cop/cops/cop.rb', line 9

def initialize(records)
  @records = records
end

Instance Attribute Details

#recordsObject (readonly)

Returns the value of attribute records.



7
8
9
# File 'lib/metatag_cop/cops/cop.rb', line 7

def records
  @records
end

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/metatag_cop/cops/cop.rb', line 13

def run
  error_msgs = []
  records.each do |record|
    error_msg = []
    parser = MetatagCop::Parser.new(record.url)
    error_msg.push error_msg(:title, record.title, parser.title)  unless parser.title == record.title
    error_msg.push error_msg(:description, record.description, parser.description) unless parser.description == record.description
    error_msg.push error_msg(:keywords, record.keywords, parser.keywords) unless parser.keywords == record.keywords
    error_msg.push error_msg(:h1, record.h1, parser.h1) unless parser.h1 == record.h1
    error_msg.unshift "url: #{record.url}" unless error_msg.empty?
    error_msgs.push error_msg unless error_msg.empty?
  end
  error_msgs
end