Class: Economy::Currency

Inherits:
Object
  • Object
show all
Defined in:
lib/economy/currency.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_codeObject (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_numberObject (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

#decimalsObject



19
20
21
# File 'lib/economy/currency.rb', line 19

def decimals
  @decimals || 2
end

#symbolObject



15
16
17
# File 'lib/economy/currency.rb', line 15

def symbol
  @symbol || '$'
end