Class: Menthol::Account
- Inherits:
-
Object
- Object
- Menthol::Account
- Defined in:
- lib/menthol/account.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(provider, name, amount, currency) ⇒ Account
constructor
A new instance of Account.
- #parse_amount(raw_amount) ⇒ Object
Constructor Details
#initialize(provider, name, amount, currency) ⇒ Account
Returns a new instance of Account.
5 6 7 8 9 10 |
# File 'lib/menthol/account.rb', line 5 def initialize(provider, name, amount, currency) @provider = provider @name = name @currency = Money::Currency.find(currency) @amount = Money.new(amount || 0, @currency.iso_code) end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
25 26 27 |
# File 'lib/menthol/account.rb', line 25 def amount @amount end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
27 28 29 |
# File 'lib/menthol/account.rb', line 27 def currency @currency end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
23 24 25 |
# File 'lib/menthol/account.rb', line 23 def name @name end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
21 22 23 |
# File 'lib/menthol/account.rb', line 21 def provider @provider end |
Class Method Details
.open(provider, configuration) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/menthol/account.rb', line 12 def self.open(provider, configuration) new( provider, configuration["name"], configuration["amount"], configuration["currency"] ) end |
Instance Method Details
#parse_amount(raw_amount) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/menthol/account.rb', line 29 def parse_amount(raw_amount) amount = raw_amount.gsub(/[^\d\.]/, "").to_f amount_subunit = amount * @currency.subunit_to_unit @amount = Money.new(amount_subunit, @currency.iso_code) end |