Class: Qif::Transaction::Split

Inherits:
Object
  • Object
show all
Defined in:
lib/qif/transaction/split.rb

Defined Under Namespace

Classes: Builder

Constant Summary collapse

SUPPORTED_FIELDS =
{
  :category => {"S" => "Category in split (Category/Transfer/Class)" },
  :memo     => {"E" => "Memo in split"                               },
  :amount   => {"$" => "Dollar amount of split"                      },
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



8
9
10
# File 'lib/qif/transaction/split.rb', line 8

def amount
  @amount
end

#categoryObject

Returns the value of attribute category.



8
9
10
# File 'lib/qif/transaction/split.rb', line 8

def category
  @category
end

#memoObject

Returns the value of attribute memo.



8
9
10
# File 'lib/qif/transaction/split.rb', line 8

def memo
  @memo
end

Instance Method Details

#to_sObject

Returns a representation of the split as it would appear in a qif file.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/qif/transaction/split.rb', line 12

def to_s()
  SUPPORTED_FIELDS.collect do |k,v|
    next unless current = instance_variable_get("@#{k}")
    field = v.keys.first
    case current.class.to_s
    when "Float"
      "#{field}#{'%.2f'%current}"
    when "String"
      current.split("\n").collect {|x| "#{field}#{x}" }
    else
      "#{field}#{current}"
    end
  end.flatten.compact.join("\n")
end