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.
Files changed (2) hide show
  1. data/bin/habiter +34 -14
  2. metadata +1 -1
data/bin/habiter CHANGED
@@ -34,9 +34,15 @@ end
34
34
  @habits = {} unless @habits
35
35
 
36
36
  options = {}
37
- OptionParser.new do |opts|
38
- opts.banner = "Usage: habiter.rb [options]"
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] = 30 unless 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
- print " " * (name_column_width + 2)
60
- (0..options[:days]).each do |i|
61
- print (day + (i)).strftime('%a')[0].chr.swapcase.colorize(36)
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(36)
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
- done_in_last_30 = 0
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
- done_in_last_30 += 1
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
- print "(#{done_in_last_30}/30)".colorize(36)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: habiter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom MacWright