Class: Paapi::Item
Instance Attribute Summary collapse
-
#hash ⇒ Object
Returns the value of attribute hash.
Class Method Summary collapse
Instance Method Summary collapse
- #actors ⇒ Object
- #artists ⇒ Object
- #asin ⇒ Object
- #authors ⇒ Object
- #brand ⇒ Object
- #contributors ⇒ Object
- #contributors_of(kind) ⇒ Object
- #detail_url ⇒ Object
- #director ⇒ Object
- #eans ⇒ Object
- #features ⇒ Object
- #get(keys) ⇒ Object
- #height ⇒ Object
- #illustrators ⇒ Object
- #image_url ⇒ Object
-
#initialize(data) ⇒ Item
constructor
A new instance of Item.
- #kindle? ⇒ Boolean
- #languages ⇒ Object
- #length ⇒ Object
- #listings ⇒ Object
- #manufacturer ⇒ Object
- #model ⇒ Object
- #narrators ⇒ Object
- #original_language ⇒ Object
- #package ⇒ Object
- #part_number ⇒ Object
- #publication_date ⇒ Object
- #published_language ⇒ Object
- #publisher ⇒ Object
- #publishers ⇒ Object
- #release_date ⇒ Object
- #title ⇒ Object
- #upcs ⇒ Object
- #weight ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(data) ⇒ Item
Returns a new instance of Item.
10 11 12 |
# File 'lib/paapi/item.rb', line 10 def initialize(data) @hash = data end |
Instance Attribute Details
#hash ⇒ Object
Returns the value of attribute hash.
6 7 8 |
# File 'lib/paapi/item.rb', line 6 def hash @hash end |
Class Method Details
Instance Method Details
#actors ⇒ Object
61 62 63 |
# File 'lib/paapi/item.rb', line 61 def actors contributors_of 'actor' end |
#artists ⇒ Object
65 66 67 |
# File 'lib/paapi/item.rb', line 65 def artists contributors_of 'artist' end |
#asin ⇒ Object
18 19 20 |
# File 'lib/paapi/item.rb', line 18 def asin get(['ASIN']) end |
#authors ⇒ Object
69 70 71 |
# File 'lib/paapi/item.rb', line 69 def contributors_of 'author' end |
#brand ⇒ Object
113 114 115 |
# File 'lib/paapi/item.rb', line 113 def brand get(%w{ItemInfo ByLineInfo Brand DisplayValue}) end |
#contributors ⇒ Object
52 53 54 |
# File 'lib/paapi/item.rb', line 52 def contributors Array(get(%w{ItemInfo ByLineInfo Contributors})) end |
#contributors_of(kind) ⇒ Object
56 57 58 59 |
# File 'lib/paapi/item.rb', line 56 def contributors_of(kind) kind = kind.to_s.gsub(/([[:alpha:]]+)/) { |w| w.downcase } contributors.select { |e| e['RoleType'] == kind }&.map { |e| e.dig('Name') }&.reject {|n| n.to_s.empty?} end |
#detail_url ⇒ Object
22 23 24 |
# File 'lib/paapi/item.rb', line 22 def detail_url get(['DetailPageURL']) end |
#director ⇒ Object
73 74 75 |
# File 'lib/paapi/item.rb', line 73 def director contributors_of 'director' end |
#eans ⇒ Object
101 102 103 |
# File 'lib/paapi/item.rb', line 101 def eans get(%w{ItemInfo ExternalIds EANs DisplayValues}) end |
#features ⇒ Object
109 110 111 |
# File 'lib/paapi/item.rb', line 109 def features get(%w{ItemInfo Features DisplayValues})&.join(' ') end |
#get(keys) ⇒ Object
153 154 155 |
# File 'lib/paapi/item.rb', line 153 def get(keys) @hash.dig(*keys) end |
#height ⇒ Object
129 130 131 132 |
# File 'lib/paapi/item.rb', line 129 def height data = get(%w{ItemInfo ProductInfo ItemDimensions Height}) [data&.dig('DisplayValue'), data&.dig('Unit')].join(' ') end |
#illustrators ⇒ Object
77 78 79 |
# File 'lib/paapi/item.rb', line 77 def illustrators contributors_of 'illustrator' end |
#image_url ⇒ Object
26 27 28 |
# File 'lib/paapi/item.rb', line 26 def image_url get(%w{Images Primary Large URL}) end |
#kindle? ⇒ Boolean
149 150 151 |
# File 'lib/paapi/item.rb', line 149 def kindle? !package.nil? && package&.include?('Kindle eBook') end |
#languages ⇒ Object
89 90 91 |
# File 'lib/paapi/item.rb', line 89 def languages get(%w{ItemInfo ContentInfo Languages DisplayValues}) end |
#length ⇒ Object
134 135 136 137 |
# File 'lib/paapi/item.rb', line 134 def length data = get(%w{ItemInfo ProductInfo ItemDimensions Length}) [data&.dig('DisplayValue'), data&.dig('Unit')].join(' ') end |
#listings ⇒ Object
14 15 16 |
# File 'lib/paapi/item.rb', line 14 def listings get(['Offers', 'Listings'])&.map {|d| Listing.new(d)} end |
#manufacturer ⇒ Object
34 35 36 |
# File 'lib/paapi/item.rb', line 34 def manufacturer get(%w{ItemInfo ByLineInfo Manufacturer DisplayValue}) end |
#model ⇒ Object
121 122 123 |
# File 'lib/paapi/item.rb', line 121 def model get(%w{ItemInfo ManufactureInfo Model DisplayValue}) end |
#narrators ⇒ Object
81 82 83 |
# File 'lib/paapi/item.rb', line 81 def narrators contributors_of 'narrator' end |
#original_language ⇒ Object
93 94 95 |
# File 'lib/paapi/item.rb', line 93 def original_language languages&.find {|l| l['Type'] == 'Original Language' }&.dig('DisplayValue') end |
#package ⇒ Object
125 126 127 |
# File 'lib/paapi/item.rb', line 125 def package get(%w{ItemInfo TechnicalInfo Formats DisplayValues}) end |
#part_number ⇒ Object
117 118 119 |
# File 'lib/paapi/item.rb', line 117 def part_number get(%w{ItemInfo ManufactureInfo ItemPartNumber DisplayValue}) end |
#publication_date ⇒ Object
42 43 44 45 |
# File 'lib/paapi/item.rb', line 42 def publication_date d = get(%w{ItemInfo ContentInfo PublicationDate DisplayValue}) return Date.parse(d) rescue nil end |
#published_language ⇒ Object
97 98 99 |
# File 'lib/paapi/item.rb', line 97 def published_language languages&.find {|l| l['Type'] == 'Published' }&.dig('DisplayValue') end |
#publisher ⇒ Object
38 39 40 |
# File 'lib/paapi/item.rb', line 38 def publisher manufacturer end |
#publishers ⇒ Object
85 86 87 |
# File 'lib/paapi/item.rb', line 85 def publishers contributors_of 'publisher' end |
#release_date ⇒ Object
47 48 49 50 |
# File 'lib/paapi/item.rb', line 47 def release_date d = get(%w{ItemInfo ProductInfo ReleaseDate DisplayValue}) return Date.parse(d) rescue nil end |
#title ⇒ Object
30 31 32 |
# File 'lib/paapi/item.rb', line 30 def title get(%w{ItemInfo Title DisplayValue}) end |
#upcs ⇒ Object
105 106 107 |
# File 'lib/paapi/item.rb', line 105 def upcs get(%w{ItemInfo ExternalIds UPCs DisplayValues}) end |
#weight ⇒ Object
144 145 146 147 |
# File 'lib/paapi/item.rb', line 144 def weight data = get(%w{ItemInfo ProductInfo ItemDimensions Weight}) [data&.dig('DisplayValue'), data&.dig('Unit')].join(' ') end |
#width ⇒ Object
139 140 141 142 |
# File 'lib/paapi/item.rb', line 139 def width data = get(%w{ItemInfo ProductInfo ItemDimensions Width}) [data&.dig('DisplayValue'), data&.dig('Unit')].join(' ') end |