Class: Marktable::Tables::HTML
- Inherits:
-
Object
- Object
- Marktable::Tables::HTML
- Defined in:
- lib/marktable/tables/html.rb
Instance Method Summary collapse
-
#initialize(html_data, headers = nil) ⇒ HTML
constructor
A new instance of HTML.
- #parse ⇒ Object
Constructor Details
#initialize(html_data, headers = nil) ⇒ HTML
Returns a new instance of HTML.
11 12 13 14 |
# File 'lib/marktable/tables/html.rb', line 11 def initialize(html_data, headers = nil) @table = extract_table_node(html_data) @headers_flag = headers end |
Instance Method Details
#parse ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/marktable/tables/html.rb', line 16 def parse return Tables::Base.blank if table.nil? || rows.empty? if has_headers? headers = extract_row_cells(first_row) data_rows = rows[1..] else headers = nil data_rows = rows end # Extract data from rows parsed_rows = data_rows.map do |row| Row.new(extract_row_cells(row), headers:) end Tables::Base::Result.new(rows: parsed_rows, headers:) end |