Class: Docp::TableDoc

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/docp/table_doc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTableDoc

Returns a new instance of TableDoc.



5
6
7
8
# File 'lib/docp/table_doc.rb', line 5

def initialize
  @doc = Nokogiri::HTML::DocumentFragment.parse ""
  @tables = []
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



4
5
6
# File 'lib/docp/table_doc.rb', line 4

def doc
  @doc
end

#tablesObject (readonly)

Returns the value of attribute tables.



4
5
6
# File 'lib/docp/table_doc.rb', line 4

def tables
  @tables
end

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/docp/table_doc.rb', line 37

def any?
  @tables.any?
end

#eachObject



18
19
20
# File 'lib/docp/table_doc.rb', line 18

def each
  @tables.each {|table| yield table }
end

#empty?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/docp/table_doc.rb', line 33

def empty?
  @tables.empty?
end

#header_required_undefinedsObject



29
30
31
# File 'lib/docp/table_doc.rb', line 29

def header_required_undefineds
  @tables.map(&:header_required_undefineds).compact
end

#parse(parse_doc, header_parser, &block) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/docp/table_doc.rb', line 10

def parse parse_doc, header_parser, &block
  Docp::Table.find(parse_doc, header_parser) do|table, header_tr, header_index|
    @tables << Docp::Table.new(@doc, header_parser, table, header_tr, header_index)
    block.call @tables.last if block_given?
  end
  self
end

#rows(&block) ⇒ Object



22
23
24
25
26
27
# File 'lib/docp/table_doc.rb', line 22

def rows &block
  @tables.map(&:rows).flatten.map {|row|
    yield row if block_given? 
    row
  }
end