Class: RakutenProductApi::Item
- Inherits:
-
Object
- Object
- RakutenProductApi::Item
- Extended by:
- Forwardable
- Defined in:
- lib/rakuten_product_api/item.rb
Instance Attribute Summary collapse
-
#raw ⇒ Object
Returns the value of attribute raw.
Instance Method Summary collapse
- #description_long ⇒ Object
- #description_short ⇒ Object
- #get(path) ⇒ Object
- #image_url ⇒ Object
-
#initialize(data) ⇒ Item
constructor
A new instance of Item.
- #isbn ⇒ Object
- #keywords ⇒ Object
- #link ⇒ Object
- #merchant ⇒ Object
- #new? ⇒ Boolean
- #price ⇒ Object
- #result_count ⇒ Object
- #rrp ⇒ Object
- #title ⇒ Object
- #upc ⇒ Object
- #used? ⇒ Boolean
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
#raw ⇒ Object
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_long ⇒ Object
49 50 51 |
# File 'lib/rakuten_product_api/item.rb', line 49 def description_long get "description/long" end |
#description_short ⇒ Object
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_url ⇒ Object
41 42 43 |
# File 'lib/rakuten_product_api/item.rb', line 41 def image_url get "imageurl" end |
#isbn ⇒ Object
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 |
#keywords ⇒ Object
53 54 55 |
# File 'lib/rakuten_product_api/item.rb', line 53 def keywords get("keywords")&.split("~~") end |
#link ⇒ Object
37 38 39 |
# File 'lib/rakuten_product_api/item.rb', line 37 def link get "linkurl" end |
#merchant ⇒ Object
16 17 18 |
# File 'lib/rakuten_product_api/item.rb', line 16 def merchant get "merchantname" end |
#new? ⇒ Boolean
61 62 63 |
# File 'lib/rakuten_product_api/item.rb', line 61 def new? !used? end |
#price ⇒ Object
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_count ⇒ Object
71 72 73 |
# File 'lib/rakuten_product_api/item.rb', line 71 def result_count @raw.at_xpath("result/item").count end |
#rrp ⇒ Object
24 25 26 |
# File 'lib/rakuten_product_api/item.rb', line 24 def rrp [at_xpath("price")&.text, at_xpath("price/@currency")&.text] end |
#title ⇒ Object
12 13 14 |
# File 'lib/rakuten_product_api/item.rb', line 12 def title get "productname" end |
#upc ⇒ Object
28 29 30 |
# File 'lib/rakuten_product_api/item.rb', line 28 def upc get "upccode" end |
#used? ⇒ Boolean
57 58 59 |
# File 'lib/rakuten_product_api/item.rb', line 57 def used? description.match?(/used/i) end |