class ConfluenceHelper::HtmlTable
Public Class Methods
new(node)
click to toggle source
# File lib/confluence_helper.rb, line 6 def initialize(node) @node = node end
Public Instance Methods
column_names()
click to toggle source
# File lib/confluence_helper.rb, line 14 def column_names @column_names ||= @node.xpath('.//tr/th').map{|n| n.text.strip} end
data()
click to toggle source
# 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:)
click to toggle source
# File lib/confluence_helper.rb, line 10 def has_columns?(columns:) column_names.sort == columns.sort end
Private Instance Methods
cell_value(cell)
click to toggle source
# File lib/confluence_helper.rb, line 33 def cell_value(cell) (cell.xpath(".//a").empty? ? cell.text : cell.inner_html).gsub("\u00C2", " ").gsub("\u00A0", " ").strip end