Class: BankSheet

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(initial_balance = Decimal.from_whole_and_part(0), date = Date.today) ⇒ BankSheet

Returns a new instance of BankSheet.



29
30
31
32
33
# File 'lib/ebutil.rb', line 29

def initialize(initial_balance = Decimal.from_whole_and_part(0), date = Date.today)
  @balance = initial_balance
  @transactions = []
  @date = date
end

Instance Attribute Details

#balanceObject (readonly)

Returns the value of attribute balance.



26
27
28
# File 'lib/ebutil.rb', line 26

def balance
  @balance
end

#dateObject (readonly)

Returns the value of attribute date.



27
28
29
# File 'lib/ebutil.rb', line 27

def date
  @date
end

#transactionsObject (readonly)

Returns the value of attribute transactions.



25
26
27
# File 'lib/ebutil.rb', line 25

def transactions
  @transactions
end

Instance Method Details

#<<(transaction) ⇒ Object



55
56
57
58
# File 'lib/ebutil.rb', line 55

def <<(transaction)
  transactions << transaction
  @balance = transaction.add_to(@balance)
end

#convert_to_eb(filename, parser, relations) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/ebutil.rb', line 35

def convert_to_eb filename, parser, relations
  extract_date_from_filename filename
  import(File.read(filename), parser)
  File.open(eb_filename(filename), "w+") do |f|
    f.write(export_to_eb(relations))
  end
end

#export_to_eb(relations) ⇒ Object



49
50
51
52
53
# File 'lib/ebutil.rb', line 49

def export_to_eb(relations)
  result = ["ingbank:#{identification} #{date.strftime("%d-%m-%Y")} \"Afschrift per #{identification}\" --saldo=#{balance.to_s}"] 
  result += transactions.collect {|t| t.export_to_eb(relations)}
  result.join(" \\\n  ")
end

#import(file_content, parser) ⇒ Object



43
44
45
46
47
# File 'lib/ebutil.rb', line 43

def import file_content, parser
  parser.parse(file_content) do |attributes|
    self << Transaction.send(type_for(attributes.delete(:type)), attributes)
  end
end