Class: Banco::Reporter
- Inherits:
-
Object
- Object
- Banco::Reporter
- Includes:
- Viewable
- Defined in:
- lib/banco/reporter.rb
Instance Attribute Summary collapse
-
#all_transactions ⇒ Object
readonly
Returns the value of attribute all_transactions.
-
#csv_file_name ⇒ Object
readonly
Returns the value of attribute csv_file_name.
-
#incoming_total ⇒ Object
readonly
Returns the value of attribute incoming_total.
-
#incoming_trans ⇒ Object
readonly
Returns the value of attribute incoming_trans.
-
#incomings ⇒ Object
readonly
Returns the value of attribute incomings.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#outgoing_total ⇒ Object
readonly
Returns the value of attribute outgoing_total.
-
#outgoing_trans ⇒ Object
readonly
Returns the value of attribute outgoing_trans.
-
#outgoings ⇒ Object
readonly
Returns the value of attribute outgoings.
Instance Method Summary collapse
-
#initialize(csv_file_name, report_name, transactions) ⇒ Reporter
constructor
A new instance of Reporter.
- #remove_blank_lines ⇒ Object
- #split_in_out ⇒ Object
- #total_incoming ⇒ Object
- #total_outgoing ⇒ Object
Methods included from Viewable
#bottom_line, #dashes, #date_range, #facts, farewell, hello, #menu, #money_in_summary, #money_out_summary, #print_summary, prompt, #save_summary_to_file, #save_transactions_to_file, #to_pounds, #transactions_all, #transactions_in, #transactions_out
Constructor Details
#initialize(csv_file_name, report_name, transactions) ⇒ Reporter
Returns a new instance of Reporter.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/banco/reporter.rb', line 21 def initialize(csv_file_name, report_name, transactions) @csv_file_name = csv_file_name @name = report_name @all_transactions = transactions @outgoing_trans = [] @incoming_trans = [] @outgoings = Hash.new(0) @incomings = Hash.new(0) puts 'formating data...' remove_blank_lines split_in_out total_outgoing total_incoming puts "\n\n" end |
Instance Attribute Details
#all_transactions ⇒ Object (readonly)
Returns the value of attribute all_transactions.
11 12 13 |
# File 'lib/banco/reporter.rb', line 11 def all_transactions @all_transactions end |
#csv_file_name ⇒ Object (readonly)
Returns the value of attribute csv_file_name.
11 12 13 |
# File 'lib/banco/reporter.rb', line 11 def csv_file_name @csv_file_name end |
#incoming_total ⇒ Object (readonly)
Returns the value of attribute incoming_total.
11 12 13 |
# File 'lib/banco/reporter.rb', line 11 def incoming_total @incoming_total end |
#incoming_trans ⇒ Object (readonly)
Returns the value of attribute incoming_trans.
11 12 13 |
# File 'lib/banco/reporter.rb', line 11 def incoming_trans @incoming_trans end |
#incomings ⇒ Object (readonly)
Returns the value of attribute incomings.
11 12 13 |
# File 'lib/banco/reporter.rb', line 11 def incomings @incomings end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/banco/reporter.rb', line 11 def name @name end |
#outgoing_total ⇒ Object (readonly)
Returns the value of attribute outgoing_total.
11 12 13 |
# File 'lib/banco/reporter.rb', line 11 def outgoing_total @outgoing_total end |
#outgoing_trans ⇒ Object (readonly)
Returns the value of attribute outgoing_trans.
11 12 13 |
# File 'lib/banco/reporter.rb', line 11 def outgoing_trans @outgoing_trans end |
#outgoings ⇒ Object (readonly)
Returns the value of attribute outgoings.
11 12 13 |
# File 'lib/banco/reporter.rb', line 11 def outgoings @outgoings end |
Instance Method Details
#remove_blank_lines ⇒ Object
37 38 39 |
# File 'lib/banco/reporter.rb', line 37 def remove_blank_lines @all_transactions.delete_if { |trans| trans..zero? && trans.moneyout.zero? } end |
#split_in_out ⇒ Object
41 42 43 |
# File 'lib/banco/reporter.rb', line 41 def split_in_out @outgoing_trans, @incoming_trans = @all_transactions.partition { |trans| trans..zero? && trans.moneyout.positive? } end |
#total_incoming ⇒ Object
50 51 52 53 |
# File 'lib/banco/reporter.rb', line 50 def total_incoming @incoming_trans.each { |trans| @incomings[trans.description[0..8]] += trans. } @incoming_total = @incomings.values.map.reduce(:+) end |
#total_outgoing ⇒ Object
45 46 47 48 |
# File 'lib/banco/reporter.rb', line 45 def total_outgoing @outgoing_trans.each { |trans| @outgoings[trans.description[0..8]] += trans.moneyout } @outgoing_total = @outgoings.values.map.reduce(:+) end |