habiter 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/habiter +34 -14
- metadata +1 -1
data/bin/habiter
CHANGED
@@ -34,9 +34,15 @@ end
|
|
34
34
|
@habits = {} unless @habits
|
35
35
|
|
36
36
|
options = {}
|
37
|
-
|
38
|
-
|
37
|
+
|
38
|
+
optparse = OptionParser.new do |opts|
|
39
|
+
opts.banner = "Usage: habiter.rb did your_habit"
|
40
|
+
options[:verbose] = false
|
41
|
+
opts.on('-v', '--verbose', "Show weekday letters for log") do
|
42
|
+
options[:verbose] = true
|
43
|
+
end
|
39
44
|
end
|
45
|
+
|
40
46
|
def did(key)
|
41
47
|
if not @habits.has_key?(key)
|
42
48
|
print "#{key} is not a habit yet. create and complete it? (y/n) "
|
@@ -53,17 +59,19 @@ end
|
|
53
59
|
|
54
60
|
|
55
61
|
def log(options={})
|
56
|
-
options[:days] =
|
62
|
+
options[:days] = 28 unless options[:days]
|
57
63
|
name_column_width = @habits.max {|a,b| a[0].length <=> b[0].length}[0].length
|
58
64
|
day = Date.today - options[:days]
|
59
|
-
|
60
|
-
|
61
|
-
|
65
|
+
if options[:verbose]
|
66
|
+
print " " * (name_column_width + 2)
|
67
|
+
(0..options[:days]).each do |i|
|
68
|
+
print (day + (i)).strftime('%a')[0].chr.swapcase.colorize(37)
|
69
|
+
end
|
70
|
+
puts
|
62
71
|
end
|
63
|
-
puts
|
64
72
|
@habits.each do |habit, times|
|
65
73
|
day = Date.today - (options[:days])
|
66
|
-
print (sprintf("%#{name_column_width}s ", habit) + "|").colorize(
|
74
|
+
print (sprintf("%#{name_column_width}s ", habit) + "|").colorize(37)
|
67
75
|
times.collect! do |time|
|
68
76
|
if time.is_a? Time
|
69
77
|
time.to_date
|
@@ -71,23 +79,35 @@ def log(options={})
|
|
71
79
|
time
|
72
80
|
end
|
73
81
|
end
|
74
|
-
|
82
|
+
done_in_last_28, week, pre_week = 0, 0, 0
|
75
83
|
(0..options[:days]).each do |i|
|
76
84
|
if times.include? day
|
77
|
-
print "+"
|
78
|
-
|
85
|
+
print "+".colorize(47)
|
86
|
+
done_in_last_28 += 1
|
87
|
+
pre_week += 1 unless i >= 20
|
88
|
+
week += 1 unless i < 20
|
79
89
|
else
|
80
|
-
print "
|
90
|
+
print "-".colorize(37)
|
81
91
|
end
|
82
92
|
day += 1
|
83
93
|
end
|
84
|
-
|
94
|
+
if ((pre_week / 3) > (week + 2))
|
95
|
+
print "|".colorize(37)
|
96
|
+
print "(#{done_in_last_28}/28)".colorize(31)
|
97
|
+
else
|
98
|
+
print "|".colorize(37)
|
99
|
+
print "(#{done_in_last_28}/28)".colorize(32)
|
100
|
+
end
|
85
101
|
puts
|
86
102
|
end
|
87
103
|
end
|
88
104
|
|
105
|
+
optparse.parse!
|
106
|
+
|
89
107
|
if ARGV[0] == 'did'
|
90
108
|
did(ARGV[1])
|
91
109
|
elsif ARGV[0] == 'log'
|
92
|
-
log()
|
110
|
+
log(options)
|
111
|
+
else
|
112
|
+
puts optparse
|
93
113
|
end
|