Class: Banco::Transaction

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date_string, description, type, moneyin, moneyout, csv_row_count) ⇒ Transaction

Returns a new instance of Transaction.



7
8
9
10
11
12
13
14
# File 'lib/banco/transaction.rb', line 7

def initialize(date_string, description, type, moneyin, moneyout, csv_row_count)
  @csv_row_count = csv_row_count
  @moneyin = convert(moneyin)
  @moneyout = convert(moneyout)
  @date = date_string
  @description = format('%-22.22s', description.upcase.to_s)
  @type = format('%-8.8s', type.upcase.to_s)
end

Instance Attribute Details

#csv_row_countObject (readonly)

Returns the value of attribute csv_row_count.



5
6
7
# File 'lib/banco/transaction.rb', line 5

def csv_row_count
  @csv_row_count
end

#dateObject (readonly)

Returns the value of attribute date.



5
6
7
# File 'lib/banco/transaction.rb', line 5

def date
  @date
end

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/banco/transaction.rb', line 5

def description
  @description
end

#moneyinObject (readonly)

Returns the value of attribute moneyin.



5
6
7
# File 'lib/banco/transaction.rb', line 5

def moneyin
  @moneyin
end

#moneyoutObject (readonly)

Returns the value of attribute moneyout.



5
6
7
# File 'lib/banco/transaction.rb', line 5

def moneyout
  @moneyout
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/banco/transaction.rb', line 5

def type
  @type
end

Instance Method Details

#convert(money) ⇒ Object



16
17
18
# File 'lib/banco/transaction.rb', line 16

def convert(money)
  money.nil? ? BigDecimal('0') : BigDecimal(money)
end

#to_sObject



20
21
22
# File 'lib/banco/transaction.rb', line 20

def to_s
  "#{date} #{type} #{description}"
end