quirk 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -0
- data/quirk.rb +4 -2
- data/quirk_test.rb +25 -6
- metadata +2 -2
data/README.md
CHANGED
@@ -13,6 +13,7 @@ Then configure your habits in a plaintext file:
|
|
13
13
|
% quirk -e
|
14
14
|
mile-run: monday, wednesday, thursday
|
15
15
|
walk-dog: everyday
|
16
|
+
; comments start with semi-colons
|
16
17
|
^quit-tv: friday
|
17
18
|
|
18
19
|
If a habit is prefixed with `^`, it means you're trying to break that habit.
|
data/quirk.rb
CHANGED
@@ -2,7 +2,7 @@ require 'date'
|
|
2
2
|
require 'colorize'
|
3
3
|
|
4
4
|
module Quirk
|
5
|
-
VERSION = '0.0.
|
5
|
+
VERSION = '0.0.3'
|
6
6
|
QUIRKFILE = ENV['QUIRKFILE'] || "#{ENV['HOME']}/.quirk"
|
7
7
|
EDITOR = ENV['EDITOR'] || 'vi'
|
8
8
|
|
@@ -59,6 +59,7 @@ module Quirk
|
|
59
59
|
|
60
60
|
def initialize(id, days, quitting)
|
61
61
|
@id, @days, @quitting, @marks = id, days, quitting, []
|
62
|
+
raise "No days found for #{id}" if @days.empty?
|
62
63
|
end
|
63
64
|
|
64
65
|
def quitting?
|
@@ -141,6 +142,7 @@ module Quirk
|
|
141
142
|
|
142
143
|
class Calendar
|
143
144
|
attr_writer :year
|
145
|
+
attr_reader :habits
|
144
146
|
|
145
147
|
def initialize(habits)
|
146
148
|
@habits = habits.reduce({}) {|hash,habit| hash[habit.id] = habit; hash}
|
@@ -227,7 +229,7 @@ module Quirk
|
|
227
229
|
text.strip.each_line do |line|
|
228
230
|
if line =~ /^\d\d\d\d\/\d\d?\/\d\d?\s+/
|
229
231
|
marks << line
|
230
|
-
elsif line !~ /^\s*$/
|
232
|
+
elsif line !~ /^\s*$/ && line !~ /^\s*;.*$/
|
231
233
|
habits << Habit.parse(line)
|
232
234
|
end
|
233
235
|
end
|
data/quirk_test.rb
CHANGED
@@ -33,9 +33,9 @@ class QuirkHabitTest < MiniTest::Unit::TestCase
|
|
33
33
|
habit.mark!(Date.new(2012, 1, 2))
|
34
34
|
habit.mark!(Date.new(2012, 1, 3))
|
35
35
|
assert_equal(:white, habit.color_on(Date.new(2012, 1, 1)))
|
36
|
-
assert_equal(:
|
36
|
+
assert_equal(:light_green, habit.color_on(Date.new(2012, 1, 2)))
|
37
37
|
assert_equal(:white, habit.color_on(Date.new(2012, 1, 3)))
|
38
|
-
assert_equal(:
|
38
|
+
assert_equal(:light_red, habit.color_on(Date.new(2012, 1, 4)))
|
39
39
|
assert_equal(:white, habit.color_on(Date.new(2012, 1, 5)))
|
40
40
|
end
|
41
41
|
|
@@ -43,13 +43,13 @@ class QuirkHabitTest < MiniTest::Unit::TestCase
|
|
43
43
|
quit = Quirk::Habit.parse('^quit-tv: sunday, monday, wednesday, thursday')
|
44
44
|
quit.mark!(Date.new(2012, 1, 2))
|
45
45
|
assert_equal(:white, quit.color_on(Date.new(2012, 1, 1)))
|
46
|
-
assert_equal(:
|
46
|
+
assert_equal(:light_red, quit.color_on(Date.new(2012, 1, 2)))
|
47
47
|
assert_equal(:white, quit.color_on(Date.new(2012, 1, 3)))
|
48
|
-
assert_equal(:
|
49
|
-
assert_equal(:
|
48
|
+
assert_equal(:light_green, quit.color_on(Date.new(2012, 1, 4)))
|
49
|
+
assert_equal(:light_green, quit.color_on(Date.new(2012, 1, 5)))
|
50
50
|
|
51
51
|
quit.mark_first!(Date.new(2012, 1, 1))
|
52
|
-
assert_equal(:
|
52
|
+
assert_equal(:light_green, quit.color_on(Date.new(2012, 1, 1)))
|
53
53
|
end
|
54
54
|
|
55
55
|
def test_streak
|
@@ -94,6 +94,25 @@ class QuirkCalendarTest < MiniTest::Unit::TestCase
|
|
94
94
|
@cal.mark!('2012/01/02 running, walk-dog')
|
95
95
|
end
|
96
96
|
|
97
|
+
def test_parse
|
98
|
+
calendar = Quirk::Calendar.parse(
|
99
|
+
"; ignore comment line\n" +
|
100
|
+
"running: everyday\n" +
|
101
|
+
"^smoking: everyday\n\n" +
|
102
|
+
"; ignore comment line\n" +
|
103
|
+
"2012/01/01 ^smoking\n" +
|
104
|
+
"2012/01/01 running\n\n")
|
105
|
+
|
106
|
+
assert(calendar.has_habit?('running'))
|
107
|
+
assert(calendar.has_habit?('smoking'))
|
108
|
+
assert_equal(Date.new(2012, 1, 1), calendar.habits['running'].first_date)
|
109
|
+
assert_equal(Date.new(2012, 1, 1), calendar.habits['smoking'].first_date)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_parse_day_error
|
113
|
+
assert_raises(RuntimeError) { Quirk::Calendar.parse('running: invalid') }
|
114
|
+
end
|
115
|
+
|
97
116
|
def test_mark
|
98
117
|
assert_equal([Date.new(2012,1,1), Date.new(2012,1,2)], @running.marks)
|
99
118
|
assert_equal([Date.new(2012,1,1), Date.new(2012,1,2)], @walking.marks)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quirk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: .
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|