-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhealth_log
executable file
·62 lines (50 loc) · 971 Bytes
/
health_log
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/ruby
require_relative 'health_log'
report_only = false
duration = nil
date = Date.today.to_s
while ARGV.any?
arg = ARGV.shift
case arg
when /^\d+$/
duration = arg.to_i
when 't'
duration ||= 1
report_only = true
when 'y'
date = (Date.today - 1).to_s
when 'r'
report_only = true
end
end
duration ||= 7
file = File.join __dir__, 'history.yml'
log = HealthLog.new file, date: date
unless report_only
puts
puts "Record a health log entry!"
puts "Valid tokens: #{log.tokens.join(', ')}"
puts
input = gets.chomp
log.entry input
puts
end
def normalize(text)
text.to_s
end
def justify(string)
(normalize(string) + ':').ljust 15
end
log.last_n_days(duration).each do |day, data|
puts; puts day
log.tokens.each do |token|
field = log.send(:keyword_mapping)[token]
value = data[field.to_sym]
puts [' ', justify(field), value].join
end
end
puts
log.graph.each do |bar|
puts bar
end
puts