Class: Gera::CurrencyRate
Overview
Базовый курс Basic currency rate
Instance Method Summary
collapse
#currency_from, #currency_pair, #currency_pair=, #currency_to
Instance Method Details
#dump ⇒ Object
70
71
72
|
# File 'app/models/gera/currency_rate.rb', line 70
def dump
as_json(only: %i[created_at cur_from cur_to mode rate_value metadata rate_source_id]).merge external_rates: external_rates.map(&:dump)
end
|
#external_rates ⇒ Object
34
35
36
|
# File 'app/models/gera/currency_rate.rb', line 34
def external_rates
[external_rate, external_rate1, external_rate2, external_rate3].compact
end
|
#external_rates=(rates) ⇒ Object
30
31
32
|
# File 'app/models/gera/currency_rate.rb', line 30
def external_rates=(rates)
self.external_rate, self.external_rate1, self.external_rate2, self.external_rate3 = rates
end
|
#humanized_rate ⇒ Object
62
63
64
65
66
67
68
|
# File 'app/models/gera/currency_rate.rb', line 62
def humanized_rate
if rate_value < 1
"#{rate_value} (1/#{1.0 / rate_value})"
else
rate_value
end
end
|
#in_money ⇒ Object
46
47
48
|
# File 'app/models/gera/currency_rate.rb', line 46
def in_money
reverse_rate_money.to_d > 1 ? reverse_rate_money : 1
end
|
#inspect ⇒ Object
42
43
44
|
# File 'app/models/gera/currency_rate.rb', line 42
def inspect
"#{currency_pair}:#{humanized_rate}"
end
|
74
75
76
|
# File 'app/models/gera/currency_rate.rb', line 74
def meta
@meta ||= OpenStruct.new metadata.deep_symbolize_keys
end
|
#out_money ⇒ Object
50
51
52
|
# File 'app/models/gera/currency_rate.rb', line 50
def out_money
rate_money.to_d > 1 ? rate_money : 1
end
|
#rate_money ⇒ Object
54
55
56
|
# File 'app/models/gera/currency_rate.rb', line 54
def rate_money
Money.from_amount(rate_value, cur_to)
end
|
#reverse_rate_money ⇒ Object
58
59
60
|
# File 'app/models/gera/currency_rate.rb', line 58
def reverse_rate_money
Money.from_amount(1.0 / rate_value, cur_from)
end
|
#to_s ⇒ Object
38
39
40
|
# File 'app/models/gera/currency_rate.rb', line 38
def to_s
currency_pair.to_s
end
|