Class: Miser::Movement
- Inherits:
-
Object
- Object
- Miser::Movement
- Defined in:
- lib/miser/movement.rb
Constant Summary collapse
- ZERO =
0.0
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#purpose ⇒ Object
readonly
Returns the value of attribute purpose.
Instance Method Summary collapse
- #+(amount) ⇒ Object
- #coerce(numeric) ⇒ Object
- #credit? ⇒ Boolean
- #days_from_now ⇒ Object
- #debit? ⇒ Boolean
-
#initialize(date:, amount:, purpose:) ⇒ Movement
constructor
A new instance of Movement.
- #to_s ⇒ Object
Constructor Details
#initialize(date:, amount:, purpose:) ⇒ Movement
Returns a new instance of Movement.
7 8 9 10 11 |
# File 'lib/miser/movement.rb', line 7 def initialize(date:, amount:, purpose:) @date = date @amount = amount @purpose = purpose end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
3 4 5 |
# File 'lib/miser/movement.rb', line 3 def amount @amount end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
3 4 5 |
# File 'lib/miser/movement.rb', line 3 def date @date end |
#purpose ⇒ Object (readonly)
Returns the value of attribute purpose.
3 4 5 |
# File 'lib/miser/movement.rb', line 3 def purpose @purpose end |
Instance Method Details
#+(amount) ⇒ Object
13 14 15 |
# File 'lib/miser/movement.rb', line 13 def +(amount) @amount + amount end |
#coerce(numeric) ⇒ Object
25 26 27 |
# File 'lib/miser/movement.rb', line 25 def coerce(numeric) [@amount, numeric] end |
#credit? ⇒ Boolean
21 22 23 |
# File 'lib/miser/movement.rb', line 21 def credit? @amount > ZERO end |
#days_from_now ⇒ Object
33 34 35 |
# File 'lib/miser/movement.rb', line 33 def days_from_now (DateTime.now - @date).to_f end |
#debit? ⇒ Boolean
17 18 19 |
# File 'lib/miser/movement.rb', line 17 def debit? @amount < ZERO end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/miser/movement.rb', line 29 def to_s "#{@date.to_time.utc}: #{@amount} (#{@purpose})" end |