Class: Detergent::Inspector::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/detergent/inspector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReport

Returns a new instance of Report.



25
26
27
28
29
# File 'lib/detergent/inspector.rb', line 25

def initialize
  @removals = { first_pass: [], second_pass: [] }
  @top_nodes = []
  @best_score = 0
end

Instance Attribute Details

#best_scoreObject

Returns the value of attribute best_score.



22
23
24
# File 'lib/detergent/inspector.rb', line 22

def best_score
  @best_score
end

#content_rootObject

Returns the value of attribute content_root.



22
23
24
# File 'lib/detergent/inspector.rb', line 22

def content_root
  @content_root
end

#content_root_sizeObject

Returns the value of attribute content_root_size.



22
23
24
# File 'lib/detergent/inspector.rb', line 22

def content_root_size
  @content_root_size
end

#removalsObject (readonly)

Returns the value of attribute removals.



23
24
25
# File 'lib/detergent/inspector.rb', line 23

def removals
  @removals
end

#strategyObject

Returns the value of attribute strategy.



22
23
24
# File 'lib/detergent/inspector.rb', line 22

def strategy
  @strategy
end

#titleObject

Returns the value of attribute title.



22
23
24
# File 'lib/detergent/inspector.rb', line 22

def title
  @title
end

#top_nodesObject

Returns the value of attribute top_nodes.



22
23
24
# File 'lib/detergent/inspector.rb', line 22

def top_nodes
  @top_nodes
end

Instance Method Details

#located?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/detergent/inspector.rb', line 31

def located?
  !content_root.nil?
end

#to_sObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/detergent/inspector.rb', line 35

def to_s
  lines = ["Detergent #{Detergent::VERSION} debug report"]
  lines << "Title: #{title.inspect}"
  lines << verdict
  lines << ""
  lines << removal_summary(:first_pass, "First pass (obvious junk)")
  lines << ""
  lines << "Top scoring nodes after first pass:"

  top_nodes.each do |node|
    lines << format("  %5d  %-38s %s", node.score, node.descriptor, node.preview)
    node.breakdown&.each do |label, points|
      lines << format("         %+5d  %s", points, label)
    end
  end

  lines << ""
  lines << if located?
    "Content root: #{content_root} (#{content_root_size} chars of HTML)"
  else
    "Content root: (none)"
  end
  lines << removal_summary(:second_pass, "Second pass (within content)")
  lines.join("\n")
end