Class: Banco::Reporter

Inherits:
Object
  • Object
show all
Includes:
Viewable
Defined in:
lib/banco/reporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_transactionsObject (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_nameObject (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_totalObject (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_transObject (readonly)

Returns the value of attribute incoming_trans.



11
12
13
# File 'lib/banco/reporter.rb', line 11

def incoming_trans
  @incoming_trans
end

#incomingsObject (readonly)

Returns the value of attribute incomings.



11
12
13
# File 'lib/banco/reporter.rb', line 11

def incomings
  @incomings
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/banco/reporter.rb', line 11

def name
  @name
end

#outgoing_totalObject (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_transObject (readonly)

Returns the value of attribute outgoing_trans.



11
12
13
# File 'lib/banco/reporter.rb', line 11

def outgoing_trans
  @outgoing_trans
end

#outgoingsObject (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_linesObject



37
38
39
# File 'lib/banco/reporter.rb', line 37

def remove_blank_lines
  @all_transactions.delete_if { |trans| trans.moneyin.zero? && trans.moneyout.zero? }
end

#split_in_outObject



41
42
43
# File 'lib/banco/reporter.rb', line 41

def split_in_out
  @outgoing_trans, @incoming_trans = @all_transactions.partition { |trans| trans.moneyin.zero? && trans.moneyout.positive? }
end

#total_incomingObject



50
51
52
53
# File 'lib/banco/reporter.rb', line 50

def total_incoming
  @incoming_trans.each { |trans| @incomings[trans.description[0..8]] += trans.moneyin }
  @incoming_total = @incomings.values.map.reduce(:+)
end

#total_outgoingObject



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