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
12
13
14
# File 'lib/metatag_cop/cops/cop.rb', line 9

def initialize(records)
  @records = records
  @progress = Formatador::ProgressBar.new(
    records.length, color: 'green'
  )
end

Instance Attribute Details

#progressObject (readonly)

Returns the value of attribute progress.



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

def progress
  @progress
end

#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



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/metatag_cop/cops/cop.rb', line 16

def run
  results = []
  records.each do |record|
    result = []
    parser = MetatagCop::Parser.new(record.url)

    result.push error_msg(:title, record.title, parser.title) unless parser.title == record.title
    result.push error_msg(:description, record.description, parser.description) unless parser.description == record.description
    result.push error_msg(:keywords, record.keywords, parser.keywords) unless parser.keywords == record.keywords
    result.push error_msg(:h1, record.h1, parser.h1) unless parser.h1 == record.h1

    results.unshift({ url: record.url, res: result }) unless result.empty?

    progress.increment
  end

  kosi = Kosi::Table.new(connector_char: '-', separate_each_row: true)
  results.each do |result|
    Formatador.display_line("[red]#{result[:url]}[/]")
    result[:res].each do |error|
      print kosi.render(error)
    end
  end
end