21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/exact_hours/commands.rb', line 21
def prepare_for_import(weekfile)
clients_ids = get_clients weekfile
year,week_num = get_date_from_weekfile weekfile
weekdata = YAML.load_file(weekfile)
table = Text::Table.new
table.head = ['Account','Date','Employee','Item','Notes','Project','Quantity']
weekdata["days"].each do | day, blocks |
blocks.each do | block |
table.rows << [clients_ids[block['client']], get_date(year, week_num, day), weekdata['employee'], block['type'],block['note'], block['project'], block['qty']]
end
end
print table.to_s
csv_string = CSV.generate force_quotes: false , col_sep: ";" do |csv|
table.rows.each do | row |
csv << row
end
end
csvfile = File.join File.dirname(weekfile), 'exact_hours.csv'
File.open(csvfile, "wb") do |f|
f.write(csv_string)
end
end
|