Class: Gera::RateFromMultiplicator

Inherits:
Object
  • Object
show all
Includes:
Mathematic
Defined in:
lib/gera/rate_from_multiplicator.rb

Direct Known Subclasses

Rate

Constant Summary collapse

FORMAT_ROUND =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Constructor Details

#initialize(value) ⇒ RateFromMultiplicator

Returns a new instance of RateFromMultiplicator.



10
11
12
# File 'lib/gera/rate_from_multiplicator.rb', line 10

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'lib/gera/rate_from_multiplicator.rb', line 4

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



14
15
16
# File 'lib/gera/rate_from_multiplicator.rb', line 14

def ==(other)
  value == other.value
end

#exchange(amount, currency) ⇒ Object



26
27
28
# File 'lib/gera/rate_from_multiplicator.rb', line 26

def exchange(amount, currency)
  money_exchange to_d, amount, currency
end

#format(cur1 = '', cur2 = '') ⇒ Object



40
41
42
43
44
# File 'lib/gera/rate_from_multiplicator.rb', line 40

def format(cur1='', cur2='')
  cur1 = " #{cur1}" if cur1.present?
  cur2 = " #{cur2}" if cur2.present?
  "#{in_amount.round FORMAT_ROUND}#{cur1}#{out_amount.round FORMAT_ROUND}#{cur2}"
end

#in_amountObject



18
19
20
# File 'lib/gera/rate_from_multiplicator.rb', line 18

def in_amount
  value > 1 ? 1.0 : 1.0 / value
end

#out_amountObject



22
23
24
# File 'lib/gera/rate_from_multiplicator.rb', line 22

def out_amount
  value > 1 ? value : 1.0
end

#reverseObject



34
35
36
# File 'lib/gera/rate_from_multiplicator.rb', line 34

def reverse
  self.class.new(1.0 / value).freeze
end

#reverse_exchange(amount, currency) ⇒ Object



30
31
32
# File 'lib/gera/rate_from_multiplicator.rb', line 30

def reverse_exchange(amount, currency)
  money_reverse_exchange to_d, amount, currency
end

#to_rateObject



50
51
52
# File 'lib/gera/rate_from_multiplicator.rb', line 50

def to_rate
  self
end

#to_sObject



46
47
48
# File 'lib/gera/rate_from_multiplicator.rb', line 46

def to_s
  format
end