Class: BankSheet
- Inherits:
-
Object
- Object
- BankSheet
- Defined in:
- lib/ebutil.rb
Instance Attribute Summary collapse
-
#balance ⇒ Object
readonly
Returns the value of attribute balance.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#transactions ⇒ Object
readonly
Returns the value of attribute transactions.
Instance Method Summary collapse
- #<<(transaction) ⇒ Object
- #convert_to_eb(filename, parser, relations) ⇒ Object
- #export_to_eb(relations) ⇒ Object
- #import(file_content, parser) ⇒ Object
-
#initialize(initial_balance = Decimal.from_whole_and_part(0), date = Date.today) ⇒ BankSheet
constructor
A new instance of BankSheet.
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
#balance ⇒ Object (readonly)
Returns the value of attribute balance.
26 27 28 |
# File 'lib/ebutil.rb', line 26 def balance @balance end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
27 28 29 |
# File 'lib/ebutil.rb', line 27 def date @date end |
#transactions ⇒ Object (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 |