Class: ApiBucket::Rakuten::Item
- Inherits:
-
Base::Item
- Object
- Base::Item
- ApiBucket::Rakuten::Item
- Defined in:
- lib/api_bucket/rakuten/item.rb
Instance Attribute Summary
Attributes inherited from Base::Item
#availablity, #description, #detail_url, #image, #image_l, #image_m, #image_s, #preview_url, #price, #product_code, #release_date, #title
Instance Method Summary collapse
-
#initialize(element) ⇒ Item
constructor
A new instance of Item.
Methods inherited from Base::Item
Constructor Details
#initialize(element) ⇒ Item
Returns a new instance of Item.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/api_bucket/rakuten/item.rb', line 7 def initialize(element) @product_code = element['itemCode'] @detail_url = element['itemUrl'] @preview_url = '' @price = element['itemPrice'] @title = element['itemName'] # image # ex(http://thumbnail.image.rakuten.co.jp/@0_mall/ajewelry/cabinet/cddvd15/vibl-501.jpg?_ex=64x64) @image = {} keys = { l: 'mediumImageUrls', m: 'mediumImageUrls', s: 'smallImageUrls' } keys.each do |key, image_key| if element.has_key?(image_key) and element[image_key].present? matches = element[image_key].first['imageUrl'].match(/(.+)\?_ex=(\d+)x(\d+)/) image_url_no_params = matches[1] size = matches[2] if key == :l @image[key] = { url: image_url_no_params, width: 500, height: 500} elsif key == :m @image[key] = { url: element[image_key].first['imageUrl'], width: size, height: size} elsif key == :s @image[key] = {url: element[image_key].first['imageUrl'], width: size, height: size} end else @image[key] = {url: nil, width: 0, height: 0} end end @description = element['itemCaption'] @release_date = '' if element['availability'] == 1 @availablity = "販売可能" else @availablity = "販売不可能" end end |