Class: Financial::FinancialTable
- Inherits:
-
Object
- Object
- Financial::FinancialTable
- Extended by:
- Forwardable
- Includes:
- Terminal::Table::TableHelper
- Defined in:
- lib/financial/financial_table.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Returns the value of attribute account.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#locale ⇒ Object
readonly
Returns the value of attribute locale.
-
#print_table ⇒ Object
readonly
Returns the value of attribute print_table.
Instance Method Summary collapse
- #add_balance_to_table ⇒ Object
- #add_events_to_table ⇒ Object
- #add_rows(terminal_table) ⇒ Object
- #add_rows_in_date(date, options) ⇒ Object
- #final_balance ⇒ Object
- #hifen ⇒ Object
- #initial_balance ⇒ Object
-
#initialize(account_instance, print_table_instance) ⇒ FinancialTable
constructor
A new instance of FinancialTable.
- #positive? ⇒ Boolean
- #received_deposit ⇒ Object
- #row_date ⇒ Object
- #row_name ⇒ Object
- #row_value ⇒ Object
- #to_s ⇒ Object
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(account_instance, print_table_instance) @account = account_instance @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
#account ⇒ Object (readonly)
Returns the value of attribute account.
4 5 6 |
# File 'lib/financial/financial_table.rb', line 4 def account @account end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
4 5 6 |
# File 'lib/financial/financial_table.rb', line 4 def header @header end |
#locale ⇒ Object (readonly)
Returns the value of attribute locale.
4 5 6 |
# File 'lib/financial/financial_table.rb', line 4 def locale @locale end |
#print_table ⇒ Object (readonly)
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_table ⇒ Object
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_table ⇒ Object
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, ) @date = date @terminal_table = [:using] @events = events_in_date(date) unless @events.empty? add_events_to_table @terminal_table.add_separator add_balance_to_table end end |
#final_balance ⇒ Object
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(account.last_balance_in_date(final_date))] end |
#hifen ⇒ Object
79 80 81 |
# File 'lib/financial/financial_table.rb', line 79 def hifen '--------' end |
#initial_balance ⇒ Object
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
24 25 26 |
# File 'lib/financial/financial_table.rb', line 24 def positive? @positive end |
#received_deposit ⇒ Object
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.account_name}" value = value.gsub('-', '+') end [name, value] end |
#row_date ⇒ Object
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_name ⇒ Object
91 92 93 |
# File 'lib/financial/financial_table.rb', line 91 def row_name received_deposit.first end |
#row_value ⇒ Object
95 96 97 |
# File 'lib/financial/financial_table.rb', line 95 def row_value received_deposit.last end |
#to_s ⇒ Object
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 |