class Banco::Reader

Attributes

all_from_csv[R]
csv_file_name[R]
report_name[R]

Public Class Methods

new(csv_file_name, report_name) click to toggle source
# File lib/banco/reader.rb, line 12
def initialize(csv_file_name, report_name)
  @csv_file_name = csv_file_name
  @report_name = report_name
  @all_from_csv = []
end

Public Instance Methods

non_numeric_in_csv(exception, row_number) click to toggle source
# File lib/banco/reader.rb, line 49
def non_numeric_in_csv(exception, row_number)
  reason = exception.message.split(':')
  puts "Please check row #{row_number} of #{@csv_file_name},"
  puts "#{reason.last} should be a numeric value".rjust(54)
end
read_in_csv_data() click to toggle source
# File lib/banco/reader.rb, line 18
def read_in_csv_data
  @csv_row_count = 1

  CSV.foreach(csv_file_name) do |row|
    all_from_csv << Transaction.new(row[0], row[1], row[2], row[3], row[4], @csv_row_count)
    @csv_row_count += 1
  end
  rescue ArgumentError => e
    non_numeric_in_csv(e, @csv_row_count)
    puts "sorted ? ('y' to continue or 'q' to exit)".rjust(54)
    input = gets.chomp.downcase
    @all_from_csv = []
    input == 'y' ? retry : Viewable.farewell
  rescue Errno::ENOENT => e
    puts "Can't find file #{@csv_file_name} - have another go or (q) quit\n\n"
    loop do
      input = gets.chomp.downcase
      case input
      when 'q'
        Viewable.farewell
        exit
      when /([^\s]+(\.csv)$)/
        @csv_file_name = input
        break
      else
        puts "\ninvalid file - try again or 'q' to quit\n\n"
      end
    end
  retry
end