Class: ARBookFinder::SearchResultsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/ar_book_finder/search_results_parser.rb

Constant Summary collapse

SEARCH_ROOT_XPATH =
'//*[@id="ctl00_ContentPlaceHolder1_pnlSearchFormPanel"]'
SEARCH_PAGE_COUNT_XPATH =
'//*[@id="ctl00_ContentPlaceHolder1_ucSeachResults_lblResultsSummaryTop"]'
SEARCH_RESULTS_COUNT =
'//*[@id="ctl00_ContentPlaceHolder1_ucSearchResultsHeader_lblResultSummary"]'
SEARCH_RESULTS_XPATH =
'//*[@id="ctl00_ContentPlaceHolder1_ucSeachResults_lblQuizzes"]/table'
COLLECTION_ROOT_XPATH =
'//*[@id="ctl00_ContentPlaceHolder1_ucCollection_pnlSearchFormPanel"]'
COLLECTION_PAGE_COUNT_XPATH =
'//*[@id="ctl00_ContentPlaceHolder1_ucCollection_ucSeachResults_lblResultsSummaryTop"]'
COLLECTION_RESULTS_COUNT =
'//*[@id="ctl00_ContentPlaceHolder1_ucCollection_ucSearchResultsHeader_lblResultSummary"]'
COLLECTION_RESULTS_XPATH =
'//*[@id="ctl00_ContentPlaceHolder1_ucCollection_ucSeachResults_lblQuizzes"]/table'
BOOK_XPATH =
'tbody/tr/td[2]'
BOOK_DETAIL_XPATH =
'table/tbody/tr/td[2]'
BOOK_URL_XPATH =
'a'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(html, collection = false) ⇒ SearchResultsParser

Returns a new instance of SearchResultsParser.



19
20
21
22
23
24
# File 'lib/ar_book_finder/search_results_parser.rb', line 19

def initialize(html, collection = false)
  @doc = Nokogiri::HTML.parse(html)
  @xpath_const = collection ? :COLLECTION : :SEARCH
  @root = @doc.xpath(self.class.const_get(:"#{@xpath_const}_ROOT_XPATH"))
  @books = []
end

Instance Attribute Details

#booksObject (readonly)

Returns the value of attribute books.



17
18
19
# File 'lib/ar_book_finder/search_results_parser.rb', line 17

def books
  @books
end

#current_pageObject (readonly)

Returns the value of attribute current_page.



17
18
19
# File 'lib/ar_book_finder/search_results_parser.rb', line 17

def current_page
  @current_page
end

#page_countObject (readonly)

Returns the value of attribute page_count.



17
18
19
# File 'lib/ar_book_finder/search_results_parser.rb', line 17

def page_count
  @page_count
end

#total_booksObject (readonly)

Returns the value of attribute total_books.



17
18
19
# File 'lib/ar_book_finder/search_results_parser.rb', line 17

def total_books
  @total_books
end

Instance Method Details

#parseObject



26
27
28
29
30
31
32
# File 'lib/ar_book_finder/search_results_parser.rb', line 26

def parse
  @current_page = parse_current_page.to_i
  @page_count = parse_page_count.to_i
  @total_books = parse_total_books.to_i
  @books = parse_results
  self
end