ruby - split data and split date from text file
I have a csv data file with following data
id,account_number,balance,date
1,ar161429,482.29,11/28/2007 15:54
2,ar182364,266.93,10/9/2007 15:54
3,ar106644,887.78,10/23/2007 15:54
I am trying to create array for date & acc number and then break date
further into day, months & year. I was able to split data based on "," and
create array for acc & date but when I further try to split date into
month and day split is not working. Here's my code
class Account
puts "Please Enter the name of account file in .txt format"
balance_file = gets.chomp
@number_lines = File.read(balance_file).scan(/\n/).count
@number_lines = @number_lines - 1
File.open(balance_file) do |aFile|
@@balance = []
@@balance_due = []
@@balance_due_day = []
@@balance_due_month =[]
@@balance_due_year = []
aFile.each_line do |line|
@@balance << line.split(",").values_at(2)
@@balance_due << line.split(",").values_at(3)
puts @@balance_due
end
i = 1
begin
@@balance_due_day[i] = @@balance_due[i].split("/").values_at(0)
@@balance_due_month[i] = @@balance_due[i].slice!(3,2)
i +=1
end while i<@number_lines
end
end
No comments:
Post a Comment