Class: Lightspeed::Prices
- Inherits:
-
Object
- Object
- Lightspeed::Prices
show all
- Defined in:
- lib/lightspeed/prices.rb
Instance Method Summary
collapse
Constructor Details
#initialize(attributes) ⇒ Prices
Returns a new instance of Prices.
8
9
10
|
# File 'lib/lightspeed/prices.rb', line 8
def initialize(attributes)
@attributes = attributes
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
37
38
39
40
41
42
43
|
# File 'lib/lightspeed/prices.rb', line 37
def method_missing(method, *args, &block)
if prices.keys.include?(method)
prices[method]
else
super
end
end
|
Instance Method Details
#[](key) ⇒ Object
25
26
27
|
# File 'lib/lightspeed/prices.rb', line 25
def [](key)
prices[key]
end
|
#as_json ⇒ Object
Also known as:
to_h
16
17
18
|
# File 'lib/lightspeed/prices.rb', line 16
def as_json
attributes
end
|
#inspect ⇒ Object
29
30
31
|
# File 'lib/lightspeed/prices.rb', line 29
def inspect
prices.inspect
end
|
#prices ⇒ Object
12
13
14
|
# File 'lib/lightspeed/prices.rb', line 12
def prices
@prices ||= @attributes["ItemPrice"].map { |v| [v["useType"].parameterize.underscore.to_sym, BigDecimal(v["amount"])] }.to_h
end
|
#respond_to?(method, private_method) ⇒ Boolean
33
34
35
|
# File 'lib/lightspeed/prices.rb', line 33
def respond_to?(method, private_method)
prices.keys.include?(method) || super
end
|
#to_json ⇒ Object
21
22
23
|
# File 'lib/lightspeed/prices.rb', line 21
def to_json
Yajl::Encoder.encode(as_json)
end
|