Class: Money
- Inherits:
-
Object
- Object
- Money
- Defined in:
- lib/wahrung/money.rb,
lib/wahrung/arithmetic.rb,
lib/wahrung/comparison.rb
Overview
Comparison operations belonging to Money >, <, ==.
Class Attribute Summary collapse
-
.configuration ⇒ Object
rubocop:disable Lint/DuplicateMethods.
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#currency ⇒ Object
Returns the value of attribute currency.
Class Method Summary collapse
Instance Method Summary collapse
- #*(other) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #/(other) ⇒ Object
- #<(other) ⇒ Object
- #==(other) ⇒ Object
- #>(other) ⇒ Object
- #convert_to(currency) ⇒ Object
-
#initialize(amount, currency = Money.configuration.default_currency) ⇒ Money
constructor
A new instance of Money.
- #inspect ⇒ Object
Constructor Details
#initialize(amount, currency = Money.configuration.default_currency) ⇒ Money
Returns a new instance of Money.
24 25 26 27 |
# File 'lib/wahrung/money.rb', line 24 def initialize(amount, currency = Money.configuration.default_currency) @amount = amount @currency = currency end |
Class Attribute Details
.configuration ⇒ Object
rubocop:disable Lint/DuplicateMethods
12 13 14 |
# File 'lib/wahrung/money.rb', line 12 def configuration @configuration end |
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
5 6 7 |
# File 'lib/wahrung/money.rb', line 5 def amount @amount end |
#currency ⇒ Object
Returns the value of attribute currency.
5 6 7 |
# File 'lib/wahrung/money.rb', line 5 def currency @currency end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
16 17 18 |
# File 'lib/wahrung/money.rb', line 16 def self.configure yield configuration end |
.reset ⇒ Object
20 21 22 |
# File 'lib/wahrung/money.rb', line 20 def self.reset @configuration = Configuration.new end |
Instance Method Details
#*(other) ⇒ Object
16 17 18 |
# File 'lib/wahrung/arithmetic.rb', line 16 def *(other) formatted_result @amount * other end |
#+(other) ⇒ Object
3 4 5 |
# File 'lib/wahrung/arithmetic.rb', line 3 def +(other) formatted_result @amount + equalized_currency(other) end |
#-(other) ⇒ Object
7 8 9 |
# File 'lib/wahrung/arithmetic.rb', line 7 def -(other) formatted_result @amount - equalized_currency(other) end |
#/(other) ⇒ Object
11 12 13 14 |
# File 'lib/wahrung/arithmetic.rb', line 11 def /(other) return "0 #{@currency}" if other.zero? formatted_result @amount / other end |
#<(other) ⇒ Object
7 8 9 |
# File 'lib/wahrung/comparison.rb', line 7 def <(other) @amount < other.amount end |
#==(other) ⇒ Object
3 4 5 |
# File 'lib/wahrung/comparison.rb', line 3 def ==(other) @currency == other.currency && @amount == other.amount end |
#>(other) ⇒ Object
11 12 13 |
# File 'lib/wahrung/comparison.rb', line 11 def >(other) @amount > other.amount end |
#convert_to(currency) ⇒ Object
33 34 35 36 37 |
# File 'lib/wahrung/money.rb', line 33 def convert_to(currency) @amount = format_result((@amount * conversion(currency)).to_f) @currency = currency self end |
#inspect ⇒ Object
29 30 31 |
# File 'lib/wahrung/money.rb', line 29 def inspect formatted_result end |