Class: Cornerstore::Price
- Inherits:
-
Model::Base
- Object
- Model::Base
- Cornerstore::Price
- Includes:
- Comparable
- Defined in:
- lib/cornerstore/api/price.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#gross ⇒ Object
Returns the value of attribute gross.
-
#net ⇒ Object
Returns the value of attribute net.
-
#tax ⇒ Object
Returns the value of attribute tax.
-
#tax_rate ⇒ Object
Returns the value of attribute tax_rate.
Attributes inherited from Model::Base
#_id, #_slugs, #created_at, #parent, #updated_at
Instance Method Summary collapse
- #+(other_object) ⇒ Object
- #<=>(other_object) ⇒ Object
- #attributes ⇒ Object
- #currency_symbol ⇒ Object
- #to_f ⇒ Object
Methods inherited from Model::Base
#==, #attributes=, #initialize, #inspect, #method_missing, method_missing, #to_param, #url
Constructor Details
This class inherits a constructor from Cornerstore::Model::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Cornerstore::Model::Base
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
4 5 6 |
# File 'lib/cornerstore/api/price.rb', line 4 def amount @amount end |
#currency ⇒ Object
Returns the value of attribute currency.
4 5 6 |
# File 'lib/cornerstore/api/price.rb', line 4 def currency @currency end |
#gross ⇒ Object
Returns the value of attribute gross.
4 5 6 |
# File 'lib/cornerstore/api/price.rb', line 4 def gross @gross end |
#net ⇒ Object
Returns the value of attribute net.
4 5 6 |
# File 'lib/cornerstore/api/price.rb', line 4 def net @net end |
#tax ⇒ Object
Returns the value of attribute tax.
4 5 6 |
# File 'lib/cornerstore/api/price.rb', line 4 def tax @tax end |
#tax_rate ⇒ Object
Returns the value of attribute tax_rate.
4 5 6 |
# File 'lib/cornerstore/api/price.rb', line 4 def tax_rate @tax_rate end |
Instance Method Details
#+(other_object) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/cornerstore/api/price.rb', line 44 def +(other_object) return self if not other_object or other_object == 0 if gross Cornerstore::Price.new({ gross: gross + other_object.gross, net: net + other_object.net, currency: currency, tax_rate: other_object.tax_rate == tax_rate ? tax_rate : nil }) else Cornerstore::Price.new({ amount: amount + other_object.amount, currency: currency }) end end |
#<=>(other_object) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cornerstore/api/price.rb', line 33 def <=> (other_object) case other_object when Integer, Float, Fixnum self.amount <=> other_object when Cornerstore::Price self.amount <=> other_object.amount else raise ArgumentError, 'can only compare Integer, Float, Fixnum or Price objects with Price' end end |
#attributes ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/cornerstore/api/price.rb', line 17 def attributes if gross or tax_rate { gross: gross, net: net, tax_rate: tax_rate, currency: currency } else { amount: amount, currency: currency } end end |
#currency_symbol ⇒ Object
71 72 73 74 75 76 |
# File 'lib/cornerstore/api/price.rb', line 71 def currency_symbol { 'USD' => '$', 'EUR' => '€', }[currency] end |
#to_f ⇒ Object
63 64 65 |
# File 'lib/cornerstore/api/price.rb', line 63 def to_f @amount || @gross end |