class Tributa::HtmlToTributaTableTransformer

Attributes

html[R]

Public Class Methods

new(html) click to toggle source
# File lib/tributa/html_to_tributa_table_transformer.rb, line 9
def initialize(html)
  @html = html
end

Public Instance Methods

to_tributa_table() click to toggle source
# File lib/tributa/html_to_tributa_table_transformer.rb, line 13
def to_tributa_table
  Tributa::Table.new(rows)
end

Private Instance Methods

nhtml() click to toggle source
# File lib/tributa/html_to_tributa_table_transformer.rb, line 19
def nhtml
  @nhtml ||= Nokogiri::HTML(sanitize_html)
end
nokogiri_rows() click to toggle source
# File lib/tributa/html_to_tributa_table_transformer.rb, line 27
def nokogiri_rows
  nhtml.xpath('//table//tr')[2..]
end
rows() click to toggle source
# File lib/tributa/html_to_tributa_table_transformer.rb, line 23
def rows
  nokogiri_rows.map(&method(:to_tributa_table_row))
end
sanitize_html() click to toggle source
# File lib/tributa/html_to_tributa_table_transformer.rb, line 31
def sanitize_html
  @sanitize_html ||= html[/<table class=.rahmen. width=.950.>(.*)<\/table><BR><BR>/i].gsub(/<br><br>$/i, '')
end
to_tributa_table_row(nokogiri_row) click to toggle source
# File lib/tributa/html_to_tributa_table_transformer.rb, line 35
def to_tributa_table_row(nokogiri_row)
  values = nokogiri_row.xpath('td').map(&:text)
  Tributa::Table::Row.new(values)
end