Class: CbrCurrency::Currency

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code:, cost:, title:, amount: 1, date:) ⇒ Currency

Returns a new instance of Currency.

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
# File 'lib/cbr_currency/currency.rb', line 5

def initialize(code:, cost:, title:, amount: 1, date:)
  raise ArgumentError.new("some of params (code, cost, title, amount) is nil") unless code && cost && title && date

  @code = code.downcase.to_sym
  @rate = normalize_rate cost, amount
  @title = title
  @date = Date.parse(date)
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



3
4
5
# File 'lib/cbr_currency/currency.rb', line 3

def code
  @code
end

#dateObject

Returns the value of attribute date.



3
4
5
# File 'lib/cbr_currency/currency.rb', line 3

def date
  @date
end

#rateObject

Returns the value of attribute rate.



3
4
5
# File 'lib/cbr_currency/currency.rb', line 3

def rate
  @rate
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/cbr_currency/currency.rb', line 3

def title
  @title
end