Class: Kit::Table
Overview
Wraps the results table HTML. It iterates over each race-result pair, and exposes the table’s column headings.
Instance Method Summary collapse
-
#each {|race_row, result_row| ... } ⇒ Object
Yields each race-result pair from the table.
-
#headings ⇒ Array<String>
Returns a lightly-sanitized list of column headings.
-
#initialize(html) ⇒ Table
constructor
Creates a new
Table. -
#to_html ⇒ String
Returns an HTML document which only contains the table of race data.
Constructor Details
#initialize(html) ⇒ Table
Creates a new Table
13 14 15 16 |
# File 'lib/kit/table.rb', line 13 def initialize(html) @html = Nokogiri::HTML(html) @date_parser = DateParser.new end |
Instance Method Details
#each {|race_row, result_row| ... } ⇒ Object
Yields each race-result pair from the table
24 25 26 |
# File 'lib/kit/table.rb', line 24 def each(&block) race_rows.each { |race_row, result_row| block.call(race_row, result_row) } end |
#headings ⇒ Array<String>
Returns a lightly-sanitized list of column headings
31 32 33 |
# File 'lib/kit/table.rb', line 31 def headings headings_row.css('th').map { |th| th.text.scan(/\w|\s|#/).join } end |
#to_html ⇒ String
Returns an HTML document which only contains the table of race data
38 39 40 41 42 43 44 45 46 |
# File 'lib/kit/table.rb', line 38 def to_html if race_rows.any? content = headings_row.to_html + race_rows.flatten.map(&:to_html).join else content = nil end Nokogiri::HTML("<table>#{content}</table>").to_html end |