Class: BBMB::Util::Money
- Inherits:
-
Object
- Object
- BBMB::Util::Money
- Includes:
- Comparable
- Defined in:
- lib/bbmb/util/numbers.rb
Instance Attribute Summary collapse
-
#credits ⇒ Object
readonly
Returns the value of attribute credits.
Instance Method Summary collapse
- #*(other) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #/(other) ⇒ Object
- #<=>(other) ⇒ Object
-
#initialize(amount) ⇒ Money
constructor
A new instance of Money.
- #to_f ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(amount) ⇒ Money
Returns a new instance of Money.
36 37 38 |
# File 'lib/bbmb/util/numbers.rb', line 36 def initialize(amount) @credits = (amount.to_f * 100).round end |
Instance Attribute Details
#credits ⇒ Object (readonly)
Returns the value of attribute credits.
34 35 36 |
# File 'lib/bbmb/util/numbers.rb', line 34 def credits @credits end |
Instance Method Details
#*(other) ⇒ Object
51 52 53 |
# File 'lib/bbmb/util/numbers.rb', line 51 def *(other) Money.new(to_f * other.to_f) end |
#+(other) ⇒ Object
45 46 47 |
# File 'lib/bbmb/util/numbers.rb', line 45 def +(other) Money.new(to_f + other.to_f) end |
#-(other) ⇒ Object
48 49 50 |
# File 'lib/bbmb/util/numbers.rb', line 48 def -(other) Money.new(to_f - other.to_f) end |
#/(other) ⇒ Object
54 55 56 |
# File 'lib/bbmb/util/numbers.rb', line 54 def /(other) Money.new(to_f / other.to_f) end |
#<=>(other) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/bbmb/util/numbers.rb', line 57 def <=>(other) case other when Money @credits <=> other.credits else to_f <=> other.to_f end end |
#to_f ⇒ Object
39 40 41 |
# File 'lib/bbmb/util/numbers.rb', line 39 def to_f @credits.to_f / 100 end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/bbmb/util/numbers.rb', line 42 def to_s sprintf("%1.2f", to_f) end |