Class: ConfluenceHelper::HtmlTable

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

Instance Method Summary collapse

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_namesObject



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

#dataObject



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

Returns:

  • (Boolean)


10
11
12
# File 'lib/confluence_helper.rb', line 10

def has_columns?(columns:)
  column_names.sort == columns.sort
end