Class: TableParser::Table

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc, xpath_to_table = "//table[0]", options = {}) ⇒ Table

Returns a new instance of Table.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/table_parser/table.rb', line 4

def initialize(doc, xpath_to_table="//table[0]", options={})
  if options.has_key?(:header)
    header = options[:header]
  else
    header = true
  end
  
  if options.has_key?(:dup_rows)
    dup_rows = options[:dup_rows]
  else
    dup_rows = true
  end
  
  if options.has_key?(:dup_cols)
    dup_cols = options[:dup_cols]
  else
    dup_cols = true
  end

  table = Parser.extract_table(doc, xpath_to_table)
  @columns = Parser.extract_column_headers(table, dup_rows, dup_cols, header)
  @nodes = Parser.extract_nodes(table, @columns, dup_rows, dup_cols)
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



3
4
5
# File 'lib/table_parser/table.rb', line 3

def columns
  @columns
end

#nodesObject (readonly)

Returns the value of attribute nodes.



3
4
5
# File 'lib/table_parser/table.rb', line 3

def nodes
  @nodes
end

Instance Method Details

#[](index) ⇒ Object

get column by index



33
34
35
# File 'lib/table_parser/table.rb', line 33

def [](index)
  @columns[index]
end

#to_sObject



28
29
30
# File 'lib/table_parser/table.rb', line 28

def to_s
  "Table<#{@columns.collect{|h| h.to_s }.join(",")}>"
end