Class: TableParser::TableNode

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

Direct Known Subclasses

EmptyTableNode, TableColumn

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element, rowspan = nil, colspan = nil) ⇒ TableNode

Returns a new instance of TableNode.



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/table_parser/table_node.rb', line 4

def initialize(element, rowspan=nil, colspan=nil)
  @element = element
  @text = element.text.strip rescue ""
  
  if element.nil?
    @colspan = colspan || 1
    @rowspan = rowspan || 1
  else
    @colspan = colspan || element["colspan"].nil? ? 1 : element["colspan"].to_i
    @rowspan = rowspan || element["rowspan"].nil? ? 1 : element["rowspan"].to_i
  end
end

Instance Attribute Details

#colspanObject (readonly)

Returns the value of attribute colspan.



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

def colspan
  @colspan
end

#elementObject (readonly)

Returns the value of attribute element.



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

def element
  @element
end

#rowspanObject (readonly)

Returns the value of attribute rowspan.



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

def rowspan
  @rowspan
end

#textObject (readonly)

Returns the value of attribute text.



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

def text
  @text
end

Instance Method Details

#span(row, col) ⇒ Object



17
18
19
# File 'lib/table_parser/table_node.rb', line 17

def span(row, col)
  TableNode.new(element, rowspan-row, colspan-col)
end

#to_sObject



21
22
23
# File 'lib/table_parser/table_node.rb', line 21

def to_s
  "[#{@text}]"
end