Class: MineShaft::WebPage

Inherits:
Object
  • Object
show all
Defined in:
lib/mine_shaft/web_page.rb

Overview

Provides convenient interface for pulling content from a page parsed with either mechanize or nokogiri. web page.

Instance Method Summary collapse

Constructor Details

#initialize(parsed_page) ⇒ WebPage

Public: Creates new instance of WebPage class.

parsed_page - A Mechanize::Page or Nokogiri::HTML::Document object.

Returns new instance of WebPage class.



11
12
13
# File 'lib/mine_shaft/web_page.rb', line 11

def initialize(parsed_page)
  @page = parsed_page
end

Instance Method Details

#find_table(table_id) ⇒ Object

Public: Parses the page for a table with the specified HTML ID.

table_id - The HTML table ID as a String.

Examples

page.find_table('my-table-id')

Returns an instance of HTMLTable class if a table with the specified ID

is found on the page.

Raises InvalidPage if a table with the specified ID is not found.



26
27
28
29
# File 'lib/mine_shaft/web_page.rb', line 26

def find_table(table_id)
  table_content = @page.search("table##{table_id}").first
  table_content.nil? ? raise(InvalidPage) : HTMLTable.new(table_content)
end