Class: ARBookFinder::SearchResultsParser
- Inherits:
-
Object
- Object
- ARBookFinder::SearchResultsParser
- 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
-
#books ⇒ Object
readonly
Returns the value of attribute books.
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#page_count ⇒ Object
readonly
Returns the value of attribute page_count.
-
#total_books ⇒ Object
readonly
Returns the value of attribute total_books.
Instance Method Summary collapse
-
#initialize(html, collection = false) ⇒ SearchResultsParser
constructor
A new instance of SearchResultsParser.
- #parse ⇒ Object
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
#books ⇒ Object (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_page ⇒ Object (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_count ⇒ Object (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_books ⇒ Object (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
#parse ⇒ Object
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 |