Class: Gera::ExchangeRate
Constant Summary
collapse
- DEFAULT_COMISSION =
50
Class Method Summary
collapse
Instance Method Summary
collapse
#direction, #direction=
Methods included from Mathematic
#calculate_base_rate, #calculate_comission, #calculate_finite_rate, #calculate_profits, #calculate_total_using_regular_comission, #calculate_total_using_reverse_comission, #diff_percents, #money_exchange, #money_reverse_exchange
Class Method Details
.list_rates ⇒ Object
66
67
68
69
70
71
|
# File 'app/models/gera/exchange_rate.rb', line 66
def self.list_rates
order('id asc').each_with_object({}) do |er, h|
h[er.income_payment_system_id] ||= {}
h[er.income_payment_system_id][er.outcome_payment_system_id] = h.value
end
end
|
Instance Method Details
#available? ⇒ Boolean
73
74
75
|
# File 'app/models/gera/exchange_rate.rb', line 73
def available?
is_enabled?
end
|
#currency_from ⇒ Object
104
105
106
|
# File 'app/models/gera/exchange_rate.rb', line 104
def currency_from
in_currency
end
|
#currency_pair ⇒ Object
92
93
94
|
# File 'app/models/gera/exchange_rate.rb', line 92
def currency_pair
@currency_pair ||= CurrencyPair.new in_currency, out_currency
end
|
#currency_to ⇒ Object
100
101
102
|
# File 'app/models/gera/exchange_rate.rb', line 100
def currency_to
out_currency
end
|
#custom_inspect ⇒ Object
81
82
83
84
85
86
87
88
89
90
|
# File 'app/models/gera/exchange_rate.rb', line 81
def custom_inspect
{
value: value,
exchange_rate_id: id,
payment_system_to: payment_system_to.to_s,
payment_system_from: payment_system_from.to_s,
out_currency: out_currency.to_s,
in_currency: in_currency.to_s
}.to_s
end
|
#finite_rate ⇒ Object
112
113
114
|
# File 'app/models/gera/exchange_rate.rb', line 112
def finite_rate
direction_rate.rate
end
|
#in_currency ⇒ Object
108
109
110
|
# File 'app/models/gera/exchange_rate.rb', line 108
def in_currency
Money::Currency.find in_cur
end
|
#out_currency ⇒ Object
96
97
98
|
# File 'app/models/gera/exchange_rate.rb', line 96
def out_currency
Money::Currency.find out_cur
end
|
#to_s ⇒ Object
116
117
118
|
# File 'app/models/gera/exchange_rate.rb', line 116
def to_s
[in_currency, out_currency].join '/'
end
|
#update_finite_rate!(finite_rate) ⇒ Object
77
78
79
|
# File 'app/models/gera/exchange_rate.rb', line 77
def update_finite_rate!(finite_rate)
update! comission: calculate_comission(finite_rate, currency_rate.rate_value)
end
|