require 'open-uri'
require 'nokogiri'

class TableExtraction
  def initialize(url: '')
    @url = url
  end

  def tables
    tables = Nokogiri::HTML(open(@url)).css('table')
    tables.inject([]) { |arr, table| arr << table_arr(table) }
  end

  private

  def table_arr(table)
    table.css('tr').inject([]) { |arr, row| arr << row_arr(row) }
  end

  def row_arr(row)
    row.css('th', 'td').inject([]) { |arr, column| arr << column.content }
  end
end
