Class: Miser::Movement

Inherits:
Object
  • Object
show all
Defined in:
lib/miser/movement.rb

Constant Summary collapse

ZERO =
0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#amountObject (readonly)

Returns the value of attribute amount.



3
4
5
# File 'lib/miser/movement.rb', line 3

def amount
  @amount
end

#dateObject (readonly)

Returns the value of attribute date.



3
4
5
# File 'lib/miser/movement.rb', line 3

def date
  @date
end

#purposeObject (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

Returns:

  • (Boolean)


21
22
23
# File 'lib/miser/movement.rb', line 21

def credit?
  @amount > ZERO
end

#days_from_nowObject



33
34
35
# File 'lib/miser/movement.rb', line 33

def days_from_now
  (DateTime.now - @date).to_f
end

#debit?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/miser/movement.rb', line 17

def debit?
  @amount < ZERO
end

#to_sObject



29
30
31
# File 'lib/miser/movement.rb', line 29

def to_s
  "#{@date.to_time.utc}: #{@amount} (#{@purpose})"
end