Class: Economy::Currency
- Inherits:
-
Object
- Object
- Economy::Currency
- Defined in:
- lib/economy/currency.rb
Instance Attribute Summary collapse
-
#iso_code ⇒ Object
readonly
Returns the value of attribute iso_code.
-
#iso_number ⇒ Object
readonly
Returns the value of attribute iso_number.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #decimals ⇒ Object
-
#initialize(assignments) ⇒ Currency
constructor
A new instance of Currency.
- #symbol ⇒ Object
Constructor Details
#initialize(assignments) ⇒ Currency
Returns a new instance of Currency.
6 7 8 9 10 11 12 13 |
# File 'lib/economy/currency.rb', line 6 def initialize(assignments) %i(iso_code iso_number symbol decimals).each do |name| instance_variable_set "@#{name}", assignments[name] end unless iso_code raise "Iso code can't be empty" end end |
Instance Attribute Details
#iso_code ⇒ Object (readonly)
Returns the value of attribute iso_code.
4 5 6 |
# File 'lib/economy/currency.rb', line 4 def iso_code @iso_code end |
#iso_number ⇒ Object (readonly)
Returns the value of attribute iso_number.
4 5 6 |
# File 'lib/economy/currency.rb', line 4 def iso_number @iso_number end |
Instance Method Details
#==(other) ⇒ Object
23 24 25 |
# File 'lib/economy/currency.rb', line 23 def ==(other) other.is_a?(Currency) && other.iso_code == iso_code end |
#decimals ⇒ Object
19 20 21 |
# File 'lib/economy/currency.rb', line 19 def decimals @decimals || 2 end |
#symbol ⇒ Object
15 16 17 |
# File 'lib/economy/currency.rb', line 15 def symbol @symbol || '$' end |