Class: Lightspeed::Prices

Inherits:
Object
  • Object
show all
Defined in:
lib/lightspeed/prices.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Prices

Returns a new instance of Prices.



6
7
8
# File 'lib/lightspeed/prices.rb', line 6

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



35
36
37
38
39
40
41
# File 'lib/lightspeed/prices.rb', line 35

def method_missing(method, *args, &block)
  if prices.keys.include?(method)
    prices[method]
  else
    super
  end
end

Instance Method Details

#[](key) ⇒ Object



23
24
25
# File 'lib/lightspeed/prices.rb', line 23

def [](key)
  prices[key]
end

#as_jsonObject Also known as: to_h



14
15
16
# File 'lib/lightspeed/prices.rb', line 14

def as_json
  attributes
end

#inspectObject



27
28
29
# File 'lib/lightspeed/prices.rb', line 27

def inspect
  prices.inspect
end

#pricesObject



10
11
12
# File 'lib/lightspeed/prices.rb', line 10

def prices
  @prices ||= @attributes["ItemPrice"].map { |v| [v["useType"].parameterize.underscore.to_sym, BigDecimal.new(v["amount"])] }.to_h
end

#respond_to?(method, private_method) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/lightspeed/prices.rb', line 31

def respond_to?(method, private_method)
  prices.keys.include?(method) || super
end

#to_jsonObject



19
20
21
# File 'lib/lightspeed/prices.rb', line 19

def to_json
  as_json.to_json
end