Class: RakutenProductApi::Item

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/rakuten_product_api/item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Item

Returns a new instance of Item.



8
9
10
# File 'lib/rakuten_product_api/item.rb', line 8

def initialize(data)
  @raw = data
end

Instance Attribute Details

#rawObject

Returns the value of attribute raw.



4
5
6
# File 'lib/rakuten_product_api/item.rb', line 4

def raw
  @raw
end

Instance Method Details

#description_longObject



49
50
51
# File 'lib/rakuten_product_api/item.rb', line 49

def description_long
  get "description/long"
end

#description_shortObject



45
46
47
# File 'lib/rakuten_product_api/item.rb', line 45

def description_short
  get "description/short"
end

#get(path) ⇒ Object



65
66
67
68
69
# 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_urlObject



41
42
43
# File 'lib/rakuten_product_api/item.rb', line 41

def image_url
  get "imageurl"
end

#isbnObject



32
33
34
35
# 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

#keywordsObject



53
54
55
# File 'lib/rakuten_product_api/item.rb', line 53

def keywords
  get("keywords")&.split("~~")
end


37
38
39
# File 'lib/rakuten_product_api/item.rb', line 37

def link
  get "linkurl"
end

#merchantObject



16
17
18
# File 'lib/rakuten_product_api/item.rb', line 16

def merchant
  get "merchantname"
end

#new?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/rakuten_product_api/item.rb', line 61

def new?
  !used?
end

#priceObject



20
21
22
# File 'lib/rakuten_product_api/item.rb', line 20

def price
  [at_xpath("saleprice")&.text, at_xpath("saleprice/@currency")&.text]
end

#result_countObject



71
72
73
# File 'lib/rakuten_product_api/item.rb', line 71

def result_count
  @raw.at_xpath("result/item").count
end

#rrpObject



24
25
26
# File 'lib/rakuten_product_api/item.rb', line 24

def rrp
  [at_xpath("price")&.text, at_xpath("price/@currency")&.text]
end

#titleObject



12
13
14
# File 'lib/rakuten_product_api/item.rb', line 12

def title
  get "productname"
end

#upcObject



28
29
30
# File 'lib/rakuten_product_api/item.rb', line 28

def upc
  get "upccode"
end

#used?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/rakuten_product_api/item.rb', line 57

def used?
  description.match?(/used/i)
end