Class: Jensen::Product
- Inherits:
-
Flowlink::Product
- Object
- Flowlink::Product
- Jensen::Product
show all
- Defined in:
- lib/jensen.rb
Defined Under Namespace
Classes: NoPriceError, ProductError
Instance Method Summary
collapse
Constructor Details
#initialize(product) ⇒ Product
Returns a new instance of Product.
9
10
11
|
# File 'lib/jensen.rb', line 9
def initialize(product)
@product = product.to_hash
end
|
Instance Method Details
#brand ⇒ Object
61
62
63
|
# File 'lib/jensen.rb', line 61
def brand
@product['brand']
end
|
#cost_price ⇒ Object
41
42
43
|
# File 'lib/jensen.rb', line 41
def cost_price
@product['cost'].to_f
end
|
#description ⇒ Object
25
26
27
|
# File 'lib/jensen.rb', line 25
def description
@product['description'].to_s
end
|
#id ⇒ Object
13
14
15
|
# File 'lib/jensen.rb', line 13
def id
@product['upc'].to_s
end
|
#images ⇒ Object
91
92
93
94
95
96
97
|
# File 'lib/jensen.rb', line 91
def images
image_fields = @product.select { |(k, _)| k =~ /\Aimage_.+/ }
group_by_index(image_fields)
.map { |g| Hash[g.map { |k, v| [rename_image_key(k), v] }] }
.reject { |image| image['title'].nil? || image['title'].empty? } .reject { |image| image['url'].nil? || image['url'].empty? }
end
|
49
50
51
|
# File 'lib/jensen.rb', line 49
def meta_description
nil
end
|
53
54
55
|
# File 'lib/jensen.rb', line 53
def meta_keywords
nil
end
|
#name ⇒ Object
17
18
19
|
# File 'lib/jensen.rb', line 17
def name
@product['title'].to_s
end
|
#options ⇒ Object
69
70
71
72
|
# File 'lib/jensen.rb', line 69
def options
[]
end
|
#permalink ⇒ Object
45
46
47
|
# File 'lib/jensen.rb', line 45
def permalink
name.parameterize
end
|
#price ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/jensen.rb', line 29
def price
map, msrp = @product['map'], @product['msrp']
price = nil
price = map unless map.to_f.zero? price ||= msrp unless msrp.to_f.zero?
raise(NoPriceError) if price.nil?
price.to_f
end
|
#properties ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/jensen.rb', line 74
def properties
if attributes.nil?
misc_properties
else
attributes.reject { |(k, _)| k.nil? || k.empty? }
.merge(misc_properties)
end
end
|
#shipping_category ⇒ Object
57
58
59
|
# File 'lib/jensen.rb', line 57
def shipping_category
'default'
end
|
#sku ⇒ Object
21
22
23
|
# File 'lib/jensen.rb', line 21
def sku
@product['sku'].to_s
end
|
#taxons ⇒ Object
65
66
67
|
# File 'lib/jensen.rb', line 65
def taxons
@product['category'].split('&&').map { |group| group.split('|') }
end
|