Class: Tixriss::Transformer::HTML

Inherits:
Struct
  • Object
show all
Defined in:
lib/tixriss/transformer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#xmlObject

Returns the value of attribute xml

Returns:

  • (Object)

    the current value of xml



4
5
6
# File 'lib/tixriss/transformer.rb', line 4

def xml
  @xml
end

Instance Method Details

#bodyObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/tixriss/transformer.rb', line 32

def body
  "<body>\n<table class=\"table table-striped\">\n  <thead>\n    <tr>\n<th>From</th>\n<th>To</th>\n<th>Text</th>\n    </tr>\n  </thead>\n  <tbody>\n    \#{rows.join(\"\\n\")}\n  </tbody>\n</table>\n</body>\n"
end

#documentObject



28
29
30
# File 'lib/tixriss/transformer.rb', line 28

def document
  @document ||= Nokogiri::XML(xml)
end


61
62
63
# File 'lib/tixriss/transformer.rb', line 61

def footer
  '</html>'
end

#headerObject



51
52
53
54
55
56
57
58
59
# File 'lib/tixriss/transformer.rb', line 51

def header
  "<html>\n<head>\n  <title>Tixriss Report</title>\n  <link href=\"http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/css/bootstrap-combined.min.css\" rel=\"stylesheet\"/>\n</head>\n"
end


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/tixriss/transformer.rb', line 16

def links
  rows = document.xpath('//response/answer/link').map(&:to_s)
  rows.map do |row|
    node = Nokogiri::XML(row)
    url_from = node.xpath('//@url.from')
    url_to   = node.xpath('//@url.to')
    text     = node.xpath('//@text')

    [url_from, url_to, text]
  end
end

#rowsObject



9
10
11
12
13
14
# File 'lib/tixriss/transformer.rb', line 9

def rows
  links.map do |row|
    data = row.map { |cell| "<td>#{cell}</td>" }.join
    "<tr>#{data}</tr>"
  end
end

#to_sObject



5
6
7
# File 'lib/tixriss/transformer.rb', line 5

def to_s
  [header, body, footer].join "\n"
end