Class: Qif::Transaction::Builder
- Inherits:
-
Object
- Object
- Qif::Transaction::Builder
- Includes:
- Builderable
- Defined in:
- lib/qif/transaction/builder.rb
Overview
Factory class for building transactions.
txn = Qif::Transaction::Builder.new
.set_date('10/06/1983')
.set_amount('-10.0')
.set_memo('debit $10')
.add_split('jules')
.set_split_memo('half to jules')
.add_split_amount('-5.0')
.build
Instance Method Summary collapse
- #add_split(split) ⇒ Object
- #build ⇒ Object
-
#initialize(date_parser = ->(date) { Time.parse(date) }) ⇒ Builder
constructor
A new instance of Builder.
- #set_address(address) ⇒ Object (also: #set_adress)
Methods included from Builderable
Constructor Details
#initialize(date_parser = ->(date) { Time.parse(date) }) ⇒ Builder
Returns a new instance of Builder.
21 22 23 24 |
# File 'lib/qif/transaction/builder.rb', line 21 def initialize(date_parser = ->(date) { Time.parse(date) }) @date_parser = date_parser @splits = [] end |
Instance Method Details
#add_split(split) ⇒ Object
40 41 42 43 44 |
# File 'lib/qif/transaction/builder.rb', line 40 def add_split(split) Qif::Transaction::Split::Builder.new(self).set_split_category(split).tap do |builder| @splits << builder end end |
#build ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/qif/transaction/builder.rb', line 46 def build _build(Qif::Transaction.new).tap do |txn| txn.address = @address @splits.each do |split_builder| txn.add_split(split_builder.build_split) end end end |
#set_address(address) ⇒ Object Also known as: set_adress
34 35 36 37 |
# File 'lib/qif/transaction/builder.rb', line 34 def set_address(address) @address = [@address, address].compact.join("\n") self end |