Class: Gera::ExchangeRate

Inherits:
ApplicationRecord show all
Includes:
Authority::Abilities, DirectionSupport, Mathematic
Defined in:
app/models/gera/exchange_rate.rb

Constant Summary collapse

DEFAULT_COMISSION =
50

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DirectionSupport

#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_ratesObject



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

Returns:

  • (Boolean)


73
74
75
# File 'app/models/gera/exchange_rate.rb', line 73

def available?
  is_enabled?
end

#currency_fromObject



104
105
106
# File 'app/models/gera/exchange_rate.rb', line 104

def currency_from
  in_currency
end

#currency_pairObject



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_toObject



100
101
102
# File 'app/models/gera/exchange_rate.rb', line 100

def currency_to
  out_currency
end

#custom_inspectObject



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

#direction_rateObject



120
121
122
# File 'app/models/gera/exchange_rate.rb', line 120

def direction_rate
  Universe.direction_rates_repository.find_direction_rate_by_exchange_rate_id id
end

#finite_rateObject



112
113
114
# File 'app/models/gera/exchange_rate.rb', line 112

def finite_rate
  direction_rate.rate
end

#in_currencyObject



108
109
110
# File 'app/models/gera/exchange_rate.rb', line 108

def in_currency
  Money::Currency.find in_cur
end

#out_currencyObject



96
97
98
# File 'app/models/gera/exchange_rate.rb', line 96

def out_currency
  Money::Currency.find out_cur
end

#to_sObject



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