Class: Zanox::Shop
Instance Attribute Summary collapse
-
#available ⇒ Object
readonly
Returns the value of attribute available.
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#excerpt ⇒ Object
readonly
Returns the value of attribute excerpt.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#policies ⇒ Object
readonly
Returns the value of attribute policies.
-
#products_count ⇒ Object
readonly
Returns the value of attribute products_count.
-
#rank ⇒ Object
readonly
Returns the value of attribute rank.
-
#regions ⇒ Object
readonly
Returns the value of attribute regions.
-
#terms ⇒ Object
readonly
Returns the value of attribute terms.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
-
.confirmed_shops ⇒ Object
TODO: we could cache these results.
- .find(param, args = {}) ⇒ Object
- .find_by_id(id, args = {}) ⇒ Object
- .find_by_keyword(keyword, args = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(data) ⇒ Shop
constructor
-
pid (Integer) Shop ID - name (String) The name of the product - rank (Float) The rank of the shop - description (HTML) The description of the shop - excerpt (String) A short description of the shop - products_count (Integer) The number of products in stock - regions (String[]) A collection of regions where the shop is located - categories (String[]) A collection of the main categories of products - url (String) The direct link to the shop - image (String) An image representing the shop - currency (String) The currency used inside the shop - terms (HTML) The terms applied by the shop - policies (String[]) A collection of the policies followed by the shop.
-
Methods included from Hashable
Constructor Details
#initialize(data) ⇒ Shop
-
pid (Integer) Shop ID
-
name (String) The name of the product
-
rank (Float) The rank of the shop
-
description (HTML) The description of the shop
-
excerpt (String) A short description of the shop
-
products_count (Integer) The number of products in stock
-
regions (String[]) A collection of regions where the shop is located
-
categories (String[]) A collection of the main categories of products
-
url (String) The direct link to the shop
-
image (String) An image representing the shop
-
currency (String) The currency used inside the shop
-
terms (HTML) The terms applied by the shop
-
policies (String[]) A collection of the policies followed by the shop
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/zanox/resources/shop.rb', line 45 def initialize(data) @pid = data['@id'].to_i @name = data['name'] @rank = data['adrank'].to_f @description = strip_cdata(data['descriptionLocal']) @excerpt = data['description'] @products_count = data['products'].to_i @regions = [data['regions'].try { |r| r.map(&:values) }].flatten.compact @categories = [].tap do |categories| [data['categories'].try { |p| p[0]['category'] }].flatten.each do |category| categories << { id: category['@id'], name: category['$'], } end end @url = data['url'] @image = data['image'] @currency = data['currency'] @terms = strip_cdata(data['terms']) @policies = [].tap do |policies| [data['policies'].try { |p| p['policy'] }].flatten.each do |policy| policies << { id: policy['@id'], name: policy['$'], } if policy end end end |
Instance Attribute Details
#available ⇒ Object (readonly)
Returns the value of attribute available.
27 28 29 |
# File 'lib/zanox/resources/shop.rb', line 27 def available @available end |
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
27 28 29 |
# File 'lib/zanox/resources/shop.rb', line 27 def categories @categories end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
27 28 29 |
# File 'lib/zanox/resources/shop.rb', line 27 def currency @currency end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
27 28 29 |
# File 'lib/zanox/resources/shop.rb', line 27 def description @description end |
#excerpt ⇒ Object (readonly)
Returns the value of attribute excerpt.
27 28 29 |
# File 'lib/zanox/resources/shop.rb', line 27 def excerpt @excerpt end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
27 28 29 |
# File 'lib/zanox/resources/shop.rb', line 27 def image @image end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
27 28 29 |
# File 'lib/zanox/resources/shop.rb', line 27 def name @name end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
27 28 29 |
# File 'lib/zanox/resources/shop.rb', line 27 def pid @pid end |
#policies ⇒ Object (readonly)
Returns the value of attribute policies.
27 28 29 |
# File 'lib/zanox/resources/shop.rb', line 27 def policies @policies end |
#products_count ⇒ Object (readonly)
Returns the value of attribute products_count.
27 28 29 |
# File 'lib/zanox/resources/shop.rb', line 27 def products_count @products_count end |
#rank ⇒ Object (readonly)
Returns the value of attribute rank.
27 28 29 |
# File 'lib/zanox/resources/shop.rb', line 27 def rank @rank end |
#regions ⇒ Object (readonly)
Returns the value of attribute regions.
27 28 29 |
# File 'lib/zanox/resources/shop.rb', line 27 def regions @regions end |
#terms ⇒ Object (readonly)
Returns the value of attribute terms.
27 28 29 |
# File 'lib/zanox/resources/shop.rb', line 27 def terms @terms end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
27 28 29 |
# File 'lib/zanox/resources/shop.rb', line 27 def url @url end |
Class Method Details
.confirmed_shops ⇒ Object
TODO: we could cache these results
92 93 94 |
# File 'lib/zanox/resources/shop.rb', line 92 def confirmed_shops confirmed_ids.map { |id| find(id) }.flatten end |
.find(param, args = {}) ⇒ Object
76 77 78 |
# File 'lib/zanox/resources/shop.rb', line 76 def find(param, args = {}) param.is_a?(Numeric) ? find_by_id(param) : find_by_keyword(param) end |