Class: ConfluenceHelper::HtmlTable
- Inherits:
-
Object
- Object
- ConfluenceHelper::HtmlTable
- Defined in:
- lib/confluence_helper.rb
Instance Method Summary collapse
- #column_names ⇒ Object
- #data ⇒ Object
- #has_columns?(columns:) ⇒ Boolean
-
#initialize(node) ⇒ HtmlTable
constructor
A new instance of HtmlTable.
Constructor Details
#initialize(node) ⇒ HtmlTable
Returns a new instance of HtmlTable.
6 7 8 |
# File 'lib/confluence_helper.rb', line 6 def initialize(node) @node = node end |
Instance Method Details
#column_names ⇒ Object
14 15 16 |
# File 'lib/confluence_helper.rb', line 14 def column_names @column_names ||= @node.xpath('.//tr/th').map{|n| n.text.strip} end |
#data ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/confluence_helper.rb', line 18 def data @data ||= @node .xpath('.//tr') .map{|r| r.xpath('.//td').map{|cell| cell_value(cell)} } .reject{|r| r.empty? } .map{|r| column_names .each .with_index .with_object({}){ |(c,i),o| o[c] = r[i] } } end |
#has_columns?(columns:) ⇒ Boolean
10 11 12 |
# File 'lib/confluence_helper.rb', line 10 def has_columns?(columns:) column_names.sort == columns.sort end |