Class: Financial::FinancialTable

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Terminal::Table::TableHelper
Defined in:
lib/financial/financial_table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(account_instance, print_table_instance) ⇒ FinancialTable

Returns a new instance of FinancialTable.



17
18
19
20
21
22
# File 'lib/financial/financial_table.rb', line 17

def initialize(, print_table_instance)
  @account = 
  @print_table = print_table_instance
  @locale = Financial.locale
  @header = @locale.header_for(@account, @print_table.initial_date, @print_table.final_date)
end

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.



4
5
6
# File 'lib/financial/financial_table.rb', line 4

def 
  @account
end

#headerObject (readonly)

Returns the value of attribute header.



4
5
6
# File 'lib/financial/financial_table.rb', line 4

def header
  @header
end

#localeObject (readonly)

Returns the value of attribute locale.



4
5
6
# File 'lib/financial/financial_table.rb', line 4

def locale
  @locale
end

Returns the value of attribute print_table.



4
5
6
# File 'lib/financial/financial_table.rb', line 4

def print_table
  @print_table
end

Instance Method Details

#add_balance_to_tableObject



65
66
67
68
69
# File 'lib/financial/financial_table.rb', line 65

def add_balance_to_table
  balance = find_balance_in_date(@date)
  @terminal_table.add_row ['', balance.name, hifen, locale.format_coin(balance.value)]
  @terminal_table.add_separator
end

#add_events_to_tableObject



57
58
59
60
61
62
63
# File 'lib/financial/financial_table.rb', line 57

def add_events_to_table
  @events.each_with_index do |event, index|
    @event = event
    @index = index
    @terminal_table.add_row [row_date, row_name, row_value, '']
  end
end

#add_rows(terminal_table) ⇒ Object



40
41
42
43
44
# File 'lib/financial/financial_table.rb', line 40

def add_rows(terminal_table)
  initial_date.upto(final_date).each do |date|
    add_rows_in_date(date, :using => terminal_table)
  end
end

#add_rows_in_date(date, options) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/financial/financial_table.rb', line 46

def add_rows_in_date(date, options)
  @date = date
  @terminal_table = options[:using]
  @events = events_in_date(date)
  unless @events.empty?
    add_events_to_table
    @terminal_table.add_separator
    add_balance_to_table
  end
end

#final_balanceObject



75
76
77
# File 'lib/financial/financial_table.rb', line 75

def final_balance
  [date_to_s(final_date), locale.final_balance, hifen, to_coin(.last_balance_in_date(final_date))]
end

#hifenObject



79
80
81
# File 'lib/financial/financial_table.rb', line 79

def hifen
  '--------'
end

#initial_balanceObject



71
72
73
# File 'lib/financial/financial_table.rb', line 71

def initial_balance
  [date_to_s(initial_date), locale.initial_balance, hifen, to_coin(total)]
end

#positive?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/financial/financial_table.rb', line 24

def positive?
  @positive
end

#received_depositObject



99
100
101
102
103
104
105
106
107
# File 'lib/financial/financial_table.rb', line 99

def received_deposit
  name = @event.name
  value = @event.format_value
  if @event.is_a_received_deposit?(@account)
    name = "#{locale.received_deposit_name}: #{@event.}"
    value = value.gsub('-', '+')
  end
  [name, value]
end

#row_dateObject



83
84
85
86
87
88
89
# File 'lib/financial/financial_table.rb', line 83

def row_date
  if @index == 0
    date_to_s(@event.date)
  else
    '' # dont pass nothing if is the same date
  end
end

#row_nameObject



91
92
93
# File 'lib/financial/financial_table.rb', line 91

def row_name
  received_deposit.first
end

#row_valueObject



95
96
97
# File 'lib/financial/financial_table.rb', line 95

def row_value
  received_deposit.last
end

#to_sObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/financial/financial_table.rb', line 28

def to_s
  financial_table = self
  @financial_table = table do
    self.headings = financial_table.headings
    add_row(financial_table.initial_balance)
    add_separator
    financial_table.add_rows(self)
    add_separator
    add_row(financial_table.final_balance)
  end
end