Class: Tixriss::Transformer::HTML
- Inherits:
-
Struct
- Object
- Struct
- Tixriss::Transformer::HTML
- Defined in:
- lib/tixriss/transformer.rb
Instance Attribute Summary collapse
-
#xml ⇒ Object
Returns the value of attribute xml.
Instance Method Summary collapse
- #body ⇒ Object
- #document ⇒ Object
- #footer ⇒ Object
- #header ⇒ Object
- #links ⇒ Object
- #rows ⇒ Object
- #to_s ⇒ Object
Instance Attribute Details
#xml ⇒ Object
Returns the value of attribute xml
4 5 6 |
# File 'lib/tixriss/transformer.rb', line 4 def xml @xml end |
Instance Method Details
#body ⇒ Object
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 |
#document ⇒ Object
28 29 30 |
# File 'lib/tixriss/transformer.rb', line 28 def document @document ||= Nokogiri::XML(xml) end |
#footer ⇒ Object
61 62 63 |
# File 'lib/tixriss/transformer.rb', line 61 def '</html>' end |
#header ⇒ Object
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 |
#links ⇒ Object
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 |
#rows ⇒ Object
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_s ⇒ Object
5 6 7 |
# File 'lib/tixriss/transformer.rb', line 5 def to_s [header, body, ].join "\n" end |