Hello community,
This is the way my CSV file looks like:
id,name,valid_time,date
1,baiki,5:00,9/10/2009
1,baiki,1:45,9/14/2009
2,lee,6:00,9/8/2009
3,fatou,9:15,8/14/2008
3,fatou,10:15,8/13/2008
2,lee,6:00,9/7/2009
2,lee,6:55,9/6/2009
2,lee,6:00,9/8/2009
1,baiki,5:00,9/11/2009
1,baiki,4:00,9/12/2009
1,baiki,2:00,9/13/2009
3,fatou,12:15,8/13/2008
3,fatou,12:15,8/18/2008
...and this is my Ruby, FasterCSV (FCSV) approach to find unique id's
out of my CSV file and afterwards read all records from those employees,
do some calculations and then generate a ODF file (using
sandros-odf-report) per employee.
But I ran into a problem - ok, I admit it: SEVERAL PROBLEMS :-).
#!/usr/bin/ruby
require 'rubygems'
require 'odf-report'
require 'fastercsv'
version = '0.01'
puts "\nGorilla CSV Convert Version
#{version}\n================================"
if ARGV[0].to_s.empty?
puts "ERROR: No file name given. Please call me this way:\nExample: $
ruby do_payment_slips.rb july_2009.csv\n\n"
exit
else
puts "File to load: #{ARGV[0]}\n\n"
input_file = ARGV[0]
end
employee_id = []
FasterCSV.foreach(input_file, :headers => true) do |row|
employee_id.concat(row[0].to_a).uniq!
end
until employee_id.empty?
FasterCSV.foreach(input_file, :headers => true) do |row|
if row[0] == employee_id[0]
puts "value: #{row}"
next
end
employee_id.shift
end
end
Inside the if-loop, I try to print the current value of row, so, it
should be:
5 records of id 1 and
4 record of id 2 and
4 records of id 3
But I get just the records of id 1, 1, 3.
What am I missing?
Thanks for any help welcome
Baiki
···
--
Posted via http://www.ruby-forum.com/.