Class: ApiBucket::Amazon::Item

Inherits:
Base::Item show all
Defined in:
lib/api_bucket/amazon/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

Methods inherited from Base::Item

#adult?, #hash_all

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
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/api_bucket/amazon/item.rb', line 7

def initialize(element)
  @element = ApiBucket::Base::Element.new(element)

  @product_code = @element.get('ASIN')
  @detail_url = @element.get('DetailPageURL')

  # get item attributes element
  item_attributes = @element.get_element('ItemAttributes')

  # 最安値を優先的に格納する
  offers = @element.get_element('Offers/Offer/OfferListing')
  if @element.get('Offers/LowestNewPrice')
    @price = @element.get('Offers/LowestNewPrice')
  # ?????
  #elsif offers.hash('Price')
  #  @price = offers.hash('Price')['Amount']
  else
    @price= item_attributes.get('ListPrice/Amount')
  end

  @release_date = item_attributes.get('ReleaseDate')
  @title = item_attributes.get('Title')

  # image
  @image = {}
  keys = {
    l: 'LargeImage',
    m: 'MediumImage',
    s: 'SmallImage'
  }
  keys.each do |key, attr|
    image = @element.get_element(attr)
    if image

      @image[key] = {
        url:      image.get('URL'),
        width:    image.get('Width'),
        height:   image.get('Height')
      }
    else
      @image[key] = {
        url:      nil,
        width:    0,
        height:   0
      }
    end
  end

  if @element.hash('Offers/Offer/OfferListing')
    @availablity = @element.hash('Offers/Offer/OfferListing')['Availability']
  end

  editor_review = @element.get_element('EditorialReviews/EditorialReview')
  @description = editor_review.get('Content') if editor_review
end