class Taaze::TaazeBooktags

This class get the product id as an input return a list of tags Sample input with product id : 11100763252 Sample output ['轉型正義', '白色恐怖', '社會科學', '臺灣民主運動']

Constants

BOOKS_URL

Public Class Methods

new(book_id) click to toggle source
# File lib/taaze/tags.rb, line 13
def initialize(book_id)
  parse_html(book_id)
end

Public Instance Methods

tags() click to toggle source

Return a list of book's tags

# File lib/taaze/tags.rb, line 18
def tags
  @tags ||= extract_tags
end

Private Instance Methods

extract_tags() click to toggle source
# File lib/taaze/tags.rb, line 30
def extract_tags
  tags = []
  @document.xpath('//a[@class="tag"]').each do |t|
    tags << t.text
  end
  tags
end
parse_html(book_id) click to toggle source

parse the html

# File lib/taaze/tags.rb, line 25
def parse_html(book_id)
  url = BOOKS_URL + book_id
  @document = Nokogiri::HTML(open(url))
end