Class: CodeHunter::RailsBestPractices::Summarizer

Inherits:
Object
  • Object
show all
Defined in:
lib/code_hunter/rails_best_practices/summarizer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Summarizer

Returns a new instance of Summarizer.



8
9
10
# File 'lib/code_hunter/rails_best_practices/summarizer.rb', line 8

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/code_hunter/rails_best_practices/summarizer.rb', line 6

def options
  @options
end

Instance Method Details

#contentObject



48
49
50
# File 'lib/code_hunter/rails_best_practices/summarizer.rb', line 48

def content
  RailsBestPractices::TEMPORAL_PATHNAME.read
end

#find_line(element) ⇒ Object



24
25
26
# File 'lib/code_hunter/rails_best_practices/summarizer.rb', line 24

def find_line(element)
  element.css(".line").text.strip.to_i
end

#find_message(element) ⇒ Object



32
33
34
# File 'lib/code_hunter/rails_best_practices/summarizer.rb', line 32

def find_message(element)
  element.css(".message").text.strip
end

#find_path(element) ⇒ Object



28
29
30
# File 'lib/code_hunter/rails_best_practices/summarizer.rb', line 28

def find_path(element)
  element.css(".filename").text.strip
end

#find_url(element) ⇒ Object



36
37
38
# File 'lib/code_hunter/rails_best_practices/summarizer.rb', line 36

def find_url(element)
  element.css("a").first.try(:attr, "href")
end

#summarizeObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/code_hunter/rails_best_practices/summarizer.rb', line 12

def summarize
  warning_elements.map do |element|
    {
      :service => "rails_best_practices",
      :line    => find_line(element),
      :path    => find_path(element),
      :message => find_message(element),
      :url     => find_url(element),
    }
  end
end

#treeObject



44
45
46
# File 'lib/code_hunter/rails_best_practices/summarizer.rb', line 44

def tree
  Nokogiri.HTML(content)
end

#warning_elementsObject



40
41
42
# File 'lib/code_hunter/rails_best_practices/summarizer.rb', line 40

def warning_elements
  tree.css(".result tbody tr")
end