Class: Financo::N26::History

Inherits:
Object
  • Object
show all
Defined in:
lib/financo/n26/history.rb

Overview

History

Defined Under Namespace

Classes: Entry

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entries: [], loaded_at: 0) ⇒ History

Returns a new instance of History.



22
23
24
25
26
27
# File 'lib/financo/n26/history.rb', line 22

def initialize(entries: [], loaded_at: 0)
  @loaded_at = loaded_at
  @entries = (entries || []).each_with_object({}) do |e, m|
    m[e['id']] = Entry.new(*e.values_at('id', 'date', 'amount'))
  end
end

Instance Attribute Details

#loaded_atObject

Returns the value of attribute loaded_at.



20
21
22
# File 'lib/financo/n26/history.rb', line 20

def loaded_at
  @loaded_at
end

Instance Method Details

#add(id, date, amount) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/financo/n26/history.rb', line 29

def add(id, date, amount)
  p = @entries[id]
  n = @entries[id] = Entry.new(id, date, amount)

  loaded_at_ms = @loaded_at * 1000

  return :unknown if p.nil? && date < loaded_at_ms
  return :added if p.nil?
  return :modified if n != p
end

#dumpObject



40
41
42
43
44
45
# File 'lib/financo/n26/history.rb', line 40

def dump
  {
    'entries' => @entries.values,
    'loaded_at' => @loaded_at
  }.to_yaml
end