Class: Qif::Transaction::Builder

Inherits:
Object
  • Object
show all
Includes:
Builderable
Defined in:
lib/qif/transaction/builder.rb

Instance Method Summary collapse

Methods included from Builderable

included

Constructor Details

#initialize(date_parser = ->(date) { Time.parse(date) }) ⇒ Builder


8
9
10
11
12
# File 'lib/qif/transaction/builder.rb', line 8

def initialize(date_parser = ->(date) { Time.parse(date) })
  @txn = Qif::Transaction.new
  @date_parser = date_parser
  @splits = []
end

Instance Method Details

#add_split(split) ⇒ Object


29
30
31
32
33
34
# File 'lib/qif/transaction/builder.rb', line 29

def add_split(split)
  Qif::Transaction::Split::Builder.new(self).tap do |split_builder|
    @splits << split_builder
    split_builder.set_split_category(split)
  end
end

#buildObject


36
37
38
39
40
41
# File 'lib/qif/transaction/builder.rb', line 36

def build
  @splits.each do |split_builder|
    @txn.splits << split_builder.build_split
  end
  @txn
end

#set_adress(address) ⇒ Object Also known as: set_address


22
23
24
25
# File 'lib/qif/transaction/builder.rb', line 22

def set_adress(address)
  @txn.address = @txn.address ? @txn.address += "\n#{address}" : address
  self
end