Class: Matcher::HtmlFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/matcher/html_formatter.rb

Constant Summary collapse

TEMPLATE =
File.dirname(__FILE__) + '/xmatch.html.erb'

Instance Method Summary collapse

Constructor Details

#initialize(matcher, args = {}) ⇒ HtmlFormatter

Returns a new instance of HtmlFormatter.



11
12
13
14
15
# File 'lib/matcher/html_formatter.rb', line 11

def initialize(matcher, args = {})
  @matcher = matcher
  @report_dir = args[:report_dir] || '/tmp/xmatch'
  @prefix = args[:prefix]
end

Instance Method Details

#formatObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/matcher/html_formatter.rb', line 17

def format
  match_data = []
  @matcher.lhs.traverse do |elem|
    next if elem.xml?
    match_data << match_info_for(elem)
    elem.attributes.values.each { | attr | match_data << match_info_for(attr) }
  end
  match_data.sort! {|a, b| a.line <=> b.line}

  FileUtils.mkdir_p(@report_dir)
  filename = @prefix ? "#{@prefix}-xmatch.html" : "xmatch.html"
  File.open(File.join(@report_dir, filename), 'w') { |f|  f.write(generate_html(match_data)) }
end