Class: ARBookFinder::BookDetailParser

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

Constant Summary collapse

ROOT_XPATH =
'//*[@id="ctl00_ContentPlaceHolder1_ucBookDetail_detailTable"]'
BOOK_XPATH_NODES =
{
  cover: '//img[@id="ctl00_ContentPlaceHolder1_ucBookDetail_imgBookCover"]/@src',
  title: 'tbody/tr/td[3]/strong',
  author: '//*[@id="ctl00_ContentPlaceHolder1_ucBookDetail_lblAuthor"]',
  summary: '//*[@id="ctl00_ContentPlaceHolder1_ucBookDetail_lblBookSummary"]',
  ar_quiz_number: '//*[@id="ctl00_ContentPlaceHolder1_ucBookDetail_lblQuizNumber"]',
  language: '//*[@id="ctl00_ContentPlaceHolder1_ucBookDetail_lblLanguageCode"]',
  ar_quiz_availability: '//*[@id="ctl00_ContentPlaceHolder1_ucBookDetail_lblQuizStatusLabel"]',
  atos_book_level: '//*[@id="ctl00_ContentPlaceHolder1_ucBookDetail_lblBookLevel"]',
  interest_level: '//*[@id="ctl00_ContentPlaceHolder1_ucBookDetail_lblInterestLevel"]',
  ar_points: '//*[@id="ctl00_ContentPlaceHolder1_ucBookDetail_lblPoints"]',
  rating: '//*[@id="ctl00_ContentPlaceHolder1_ucBookDetail_lblRanking"]/img/@title',
  word_count: '//*[@id="ctl00_ContentPlaceHolder1_ucBookDetail_lblWordCount"]',
  type: '//*[@id="ctl00_ContentPlaceHolder1_ucBookDetail_lblFictionNonFiction"]',
  topics: '//*[@id="ctl00_ContentPlaceHolder1_ucBookDetail_lblTopicLabel"]',
  series: '//*[@id="ctl00_ContentPlaceHolder1_ucBookDetail_lblSeriesLabel"]'
}
ROOT_PUBLISHER_XPATH =
'//*[@id="ctl00_ContentPlaceHolder1_ucBookDetail_tblPublisherTable"]/tbody/tr'
PUBLISHER_XPATH_NODES =
{
  name: 'td[1]',
  lccn: 'td[2]',
  isbn: 'td[3]',
  year_published: 'td[4]',
  page_count: 'td[5]'
}

Instance Method Summary collapse

Constructor Details

#initialize(html) ⇒ BookDetailParser

Returns a new instance of BookDetailParser.



32
33
34
35
# File 'lib/ar_book_finder/book_detail_parser.rb', line 32

def initialize(html)
  @doc = Nokogiri::HTML.parse(html)
  @root = @doc.xpath(ROOT_XPATH)
end

Instance Method Details

#parseObject



37
38
39
40
41
# File 'lib/ar_book_finder/book_detail_parser.rb', line 37

def parse
  hash = parse_book_nodes
  hash[:publishers] = parse_publisher_nodes
  hash
end