Class: Amzwish::Wishlist::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/amzwish/wishlist.rb

Instance Method Summary collapse

Constructor Details

#initialize(html) ⇒ Page

Returns a new instance of Page.



33
34
35
# File 'lib/amzwish/wishlist.rb', line 33

def initialize(html)
  @page = Nokogiri::HTML(html)
end

Instance Method Details

#booksObject



42
43
44
45
46
47
48
# File 'lib/amzwish/wishlist.rb', line 42

def books
  @page.xpath('//tbody[@class="itemWrapper"]').collect do |e| 
    title = e.xpath('.//a[1]/text()').to_s
    asin = e.xpath("@name").to_s.split('.').last
    Book.new( title, asin)
  end
end

#has_next?Boolean

Returns:

  • (Boolean)


37
38
39
40
# File 'lib/amzwish/wishlist.rb', line 37

def has_next?
  # look and see if the 'Next' at the end of the page is an active link
  @page.xpath('//div[@class="pagDiv"]/span[@class="pagSide"]/a/span/text()').any?{|t| t.to_s.include?("Next")}
end