class RakutenProductApi::Item

Attributes

raw[RW]

Public Class Methods

new(data) click to toggle source
# File lib/rakuten_product_api/item.rb, line 8
def initialize(data)
  @raw = data
end

Public Instance Methods

description_long() click to toggle source
# File lib/rakuten_product_api/item.rb, line 49
def description_long
  get "description/long"
end
description_short() click to toggle source
# File lib/rakuten_product_api/item.rb, line 45
def description_short
  get "description/short"
end
get(path) click to toggle source
# File lib/rakuten_product_api/item.rb, line 65
def get(path)
  return nil if path.nil? || path.empty?

  @raw.at_xpath(path)&.text
end
image_url() click to toggle source
# File lib/rakuten_product_api/item.rb, line 41
def image_url
  get "imageurl"
end
isbn() click to toggle source
# File lib/rakuten_product_api/item.rb, line 32
def isbn
  return at_xpath("sku").text[/97[98]\d{10}/] if at_xpath("sku")&.text.match?(/97[98]\d{10}/)
  return at_xpath("keywords").text[/97[98]\d{10}/] if at_xpath("keywords").text.match?(/97[98]\d{10}/)
end
keywords() click to toggle source
# File lib/rakuten_product_api/item.rb, line 53
def keywords
  get("keywords")&.split("~~")
end
merchant() click to toggle source
# File lib/rakuten_product_api/item.rb, line 16
def merchant
  get "merchantname"
end
new?() click to toggle source
# File lib/rakuten_product_api/item.rb, line 61
def new?
  !used?
end
price() click to toggle source
# File lib/rakuten_product_api/item.rb, line 20
def price
  [at_xpath("saleprice")&.text, at_xpath("saleprice/@currency")&.text]
end
result_count() click to toggle source
# File lib/rakuten_product_api/item.rb, line 71
def result_count
  @raw.at_xpath("result/item").count
end
rrp() click to toggle source
# File lib/rakuten_product_api/item.rb, line 24
def rrp
  [at_xpath("price")&.text, at_xpath("price/@currency")&.text]
end
title() click to toggle source
# File lib/rakuten_product_api/item.rb, line 12
def title
  get "productname"
end
upc() click to toggle source
# File lib/rakuten_product_api/item.rb, line 28
def upc
  get "upccode"
end
used?() click to toggle source
# File lib/rakuten_product_api/item.rb, line 57
def used?
  description.match?(/used/i)
end