forked from Tushar-Naik/bootcamp2014-build-tool-faceoff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
45 lines (36 loc) · 1.52 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
task :default => [:per_person_charges, :per_team_charges]
file 'person_bags.data.tmp' => 'person_bags' do
sh "tail -n +2 person_bags | sed -e 's/ \+/ /g' > person_bags.data.tmp"
end
file 'bag_person.data.tmp' => 'person_bags.data.tmp' do
sh "cat person_bags.data.tmp | awk '{print $2\" \"$1}' | sort > bag_person.data.tmp"
end
file 'bag_team.data.tmp' => 'person_bags.data.tmp' do
sh "cat person_bags.data.tmp | awk '{print $2\" \"$3}' | sort > bag_team.data.tmp"
end
file 'baggage_charges.data.tmp' => 'baggage_charges' do
sh "tail -n +2 baggage_charges > baggage_charges.data.tmp"
end
file 'per_person_charges.data.tmp' => ['bag_person.data.tmp', 'baggage_charges.data.tmp'] do
sh "join -j 1 bag_person.data.tmp baggage_charges.data.tmp | awk '{print $2\" \"$3}' > per_person_charges.data.tmp"
end
file 'per_team_charges.data.tmp' => ['bag_team.data.tmp', 'baggage_charges.data.tmp'] do
sh "join -j 1 bag_team.data.tmp baggage_charges.data.tmp | awk '{print $2\" \"$3}' | sort | awk '{ if ($1 == last) { sum += $2 } else { if (last) { print last\" \"sum }; sum = 0; last = $1; }} END {print last\" \"sum }' > per_team_charges.data.tmp"
end
task :clean do
rm Dir.glob('*.tmp')
end
task :per_person_charges => 'per_person_charges.data.tmp' do
puts "Per person changes are..."
File.open('per_person_charges.data.tmp').each do |l|
puts l
end
puts ""
end
task :per_team_charges => 'per_team_charges.data.tmp' do
puts "Per team changes are..."
File.open('per_team_charges.data.tmp').each do |l|
puts l
end
puts ""
end