quirk 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.md +1 -1
- data/README.md +15 -73
- data/{quirk → bin/quirk} +1 -3
- data/{quirk.rb → lib/quirk.rb} +27 -41
- metadata +14 -22
- data/quirk_test.rb +0 -206
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0c95eaa5792bfc25d6564edb67b4d89886b7bb15
|
4
|
+
data.tar.gz: 3dbe38d53f23a061f031a64d01f94ed6497b4a27
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 52846f87cdb6eab06d4a28c01549eec005abf6d677619d7cbbc8d474d63dd26e108a60055e83a134285a20b857872a86e4012ba1e198c5342784429e2f9d6d38
|
7
|
+
data.tar.gz: 66f1b30d10f5aaafdfa584108622cba75dca66cb93c7d6253d669339bdcb4cd7a69df69a945db4793e1cbed3aafd57ccd51acd877c408f7b849ec43f8c26c9e9
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -1,29 +1,21 @@
|
|
1
|
-
Description
|
2
|
-
===========
|
1
|
+
# Description
|
3
2
|
|
4
3
|
Quirk is a command line utility for tracking good and bad habits.
|
5
4
|
|
6
|
-
Installation
|
7
|
-
============
|
5
|
+
# Installation
|
8
6
|
|
9
7
|
$ gem install quirk
|
10
8
|
|
11
9
|
Then configure your habits in a plaintext file:
|
12
10
|
|
13
11
|
$ quirk -e
|
14
|
-
mile-run: monday, wednesday, thursday
|
12
|
+
mile-run: monday, wednesday, thursday ; comments start with semi-colons
|
15
13
|
walk-dog: everyday
|
16
|
-
^quit-tv: friday ; comments start with semi-colons
|
17
14
|
|
18
|
-
By default, all this does is edit the `~/.quirk` file. You can configure
|
19
|
-
|
15
|
+
By default, all this does is edit the `~/.quirk` file. You can configure which file to use by
|
16
|
+
setting the environment variable `QUIRKFILE`.
|
20
17
|
|
21
|
-
|
22
|
-
In this case you're trying to quit TV on Fridays.
|
23
|
-
|
24
|
-
|
25
|
-
Usage
|
26
|
-
=====
|
18
|
+
# Usage
|
27
19
|
|
28
20
|
When you've done something, mark it with:
|
29
21
|
|
@@ -42,78 +34,28 @@ To see a single habit (green days are good, red is bad):
|
|
42
34
|
|
43
35
|
Looking for a specific year?
|
44
36
|
|
45
|
-
$ quirk mile-run -y 2011
|
37
|
+
$ quirk -c mile-run -y 2011
|
46
38
|
|
47
39
|
See all of your current streaks:
|
48
40
|
|
49
41
|
$ quirk
|
50
42
|
17 mile-run
|
51
43
|
3 walk-dog
|
52
|
-
-3 quit-tv
|
53
|
-
|
54
|
-
See which habits are pending for today:
|
55
|
-
|
56
|
-
$ quirk -t
|
57
|
-
mile-run
|
58
|
-
walk-dog
|
59
44
|
|
60
|
-
Habits are stored in plaintext in `~/.quirk`. You can use `quirk -e` to
|
61
|
-
|
62
|
-
by default. You can also specify the first day using `^`:
|
45
|
+
Habits are stored in plaintext in `~/.quirk`. You can use `quirk -e` to add/remove entries. Habits
|
46
|
+
start on the day of the first mark by default.
|
63
47
|
|
64
48
|
2012/01/01 walk-dog
|
65
|
-
2012/01/01 ^quit-tv
|
66
|
-
|
67
|
-
The first line means you walked the dog on `1/1`. The second line means you
|
68
|
-
started the habit of quitting TV. This is especially handy for starting
|
69
|
-
quitting habits on a green day.
|
70
|
-
|
71
|
-
You can specify the last day for a habit using `$`:
|
72
|
-
|
73
|
-
2012/01/01 ^quit-tv
|
74
|
-
2012/01/30 $quit-tv
|
75
|
-
2012/01/15 quit-tv
|
76
|
-
2012/01/16 quit-tv
|
77
|
-
|
78
|
-
The first line means on `1/1`, I'm going to start quitting TV. The second line
|
79
|
-
means I'll stop the habit on `1/30`, it's just a temporary goal for 1 month.
|
80
|
-
The last two lines means I watched TV on `1/15` and `1/16` (two red days).
|
81
|
-
|
82
|
-
Zsh Tab Completion
|
83
|
-
==================
|
84
|
-
|
85
|
-
Here's an example zsh completion function:
|
86
|
-
|
87
|
-
#compdef quirk
|
88
|
-
compadd `quirk -l`
|
89
|
-
|
90
|
-
Put this into your `site-functions` directory (wherever `$fpath` points to):
|
91
|
-
|
92
|
-
$ echo $fpath
|
93
|
-
/usr/share/zsh/site-functions /usr/share/zsh/4.3.11/functions
|
94
|
-
$ vim /usr/share/zsh/site-functions/_quirk
|
95
|
-
|
96
|
-
Tmux and Other Notifications Integration
|
97
|
-
========================================
|
98
|
-
|
99
|
-
Use `quirk -t` to see which habits are pending for today. Habits are separated
|
100
|
-
by a newline. Use `xargs` and/or `tr` to format as you see fit:
|
101
49
|
|
102
|
-
|
103
|
-
|
104
|
-
wlak-dog
|
105
|
-
$ quirk -t | xargs
|
106
|
-
mile-run walk-dog
|
107
|
-
$ quirk -t | xargs | tr " " ,
|
108
|
-
mile-run,walk-dog
|
50
|
+
The first line means you walked the dog on `1/1`. You can specify the first/last day for a habit
|
51
|
+
using the `^`/`$` prefixes:
|
109
52
|
|
110
|
-
|
111
|
-
|
53
|
+
2012/01/01 ^walk-dog
|
54
|
+
2012/01/30 $walk-dog
|
112
55
|
|
113
|
-
|
56
|
+
This means I'll start on `1/1` and end on `1/30`, it's just a temporary goal for 1 month.
|
114
57
|
|
115
|
-
License
|
116
|
-
=======
|
58
|
+
# License
|
117
59
|
|
118
60
|
Copyright Hugh Bien - http://hughbien.com.
|
119
61
|
Released under BSD License, see LICENSE.md for more info.
|
data/{quirk → bin/quirk}
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'optparse'
|
3
|
-
require File.expand_path(
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'quirk'))
|
4
4
|
|
5
5
|
ARGV.options do |o|
|
6
6
|
begin
|
@@ -11,9 +11,7 @@ ARGV.options do |o|
|
|
11
11
|
o.define_head "Track good and bad habits (v#{Quirk::VERSION})"
|
12
12
|
o.on('-c', '--calendar habit', 'show calendar') { |h| action = [:calendar, h] }
|
13
13
|
o.on('-e', '--edit', 'edit habits') { action = [:edit] }
|
14
|
-
o.on('-l', '--list', 'list habits') { action = [:list] }
|
15
14
|
o.on('-m', '--mark habit', 'mark for today') { |h| action = [:mark, h] }
|
16
|
-
o.on('-t', '--today', 'unfinished habits for today') { action = [:today] }
|
17
15
|
o.on('-y', '--year year', 'set calendar year') { |y| app.year = y }
|
18
16
|
o.on('-h', '--help', 'show this help message') { puts o; exit }
|
19
17
|
o.parse!
|
data/{quirk.rb → lib/quirk.rb}
RENAMED
@@ -2,7 +2,7 @@ require 'date'
|
|
2
2
|
require 'colorize'
|
3
3
|
|
4
4
|
module Quirk
|
5
|
-
VERSION = '0.0.
|
5
|
+
VERSION = '0.0.6'
|
6
6
|
QUIRKFILE = ENV['QUIRKFILE'] || "#{ENV['HOME']}/.quirk"
|
7
7
|
EDITOR = ENV['EDITOR'] || 'vi'
|
8
8
|
|
@@ -27,22 +27,25 @@ module Quirk
|
|
27
27
|
`#{EDITOR} #{QUIRKFILE} < \`tty\` > \`tty\``
|
28
28
|
end
|
29
29
|
|
30
|
-
def list
|
31
|
-
puts cal.list
|
32
|
-
end
|
33
|
-
|
34
30
|
def mark(habit_id)
|
35
|
-
File.
|
36
|
-
|
37
|
-
|
38
|
-
|
31
|
+
contents = File.read(@quirkfile)
|
32
|
+
return if !cal.has_habit?(habit_id)
|
33
|
+
|
34
|
+
date = Quirk.today.strftime('%Y/%m/%d')
|
35
|
+
match = contents.match(/^(#{date} .*)$/)
|
36
|
+
if match # already has date, add habit to line
|
37
|
+
old_line = match.captures[0]
|
38
|
+
ids = old_line.strip.split(/\s+/, 2)[1].split(',').map(&:strip)
|
39
|
+
ids << habit_id
|
40
|
+
ids = ids.sort.uniq
|
41
|
+
new_line = "#{date} #{ids.join(', ')}"
|
42
|
+
contents.sub!(old_line, new_line)
|
43
|
+
File.open(@quirkfile, 'w') { |f| f.print(contents) }
|
44
|
+
else
|
45
|
+
File.open(@quirkfile, 'a') { |f| f.puts("#{date} #{habit_id}") }
|
39
46
|
end
|
40
47
|
end
|
41
48
|
|
42
|
-
def today
|
43
|
-
puts cal.today if cal.today !~ /^\s*$/
|
44
|
-
end
|
45
|
-
|
46
49
|
def streaks
|
47
50
|
puts cal.streaks
|
48
51
|
end
|
@@ -61,15 +64,11 @@ module Quirk
|
|
61
64
|
class Habit
|
62
65
|
attr_reader :id, :days, :marks
|
63
66
|
|
64
|
-
def initialize(id, days
|
65
|
-
@id, @days, @
|
67
|
+
def initialize(id, days)
|
68
|
+
@id, @days, @marks = id, days, []
|
66
69
|
raise "No days found for #{id}" if @days.empty?
|
67
70
|
end
|
68
71
|
|
69
|
-
def quitting?
|
70
|
-
!!@quitting
|
71
|
-
end
|
72
|
-
|
73
72
|
def mark!(date)
|
74
73
|
@marks << date
|
75
74
|
@marks.sort
|
@@ -89,12 +88,12 @@ module Quirk
|
|
89
88
|
|
90
89
|
def pending?(date)
|
91
90
|
weekday = date.strftime("%w").to_i
|
92
|
-
|
91
|
+
days.include?(weekday) && color_on(date) != :light_green
|
93
92
|
end
|
94
93
|
|
95
94
|
def color_on(date)
|
96
|
-
hit_color =
|
97
|
-
miss_color =
|
95
|
+
hit_color = :light_green
|
96
|
+
miss_color = :light_red
|
98
97
|
last_date = [@last_date, Quirk.today].compact.min
|
99
98
|
if first_date.nil? ||
|
100
99
|
date < first_date ||
|
@@ -104,7 +103,7 @@ module Quirk
|
|
104
103
|
elsif @marks.include?(date)
|
105
104
|
hit_color
|
106
105
|
else
|
107
|
-
date == last_date
|
106
|
+
date == last_date ? :white : miss_color
|
108
107
|
end
|
109
108
|
end
|
110
109
|
|
@@ -132,10 +131,8 @@ module Quirk
|
|
132
131
|
line.strip!
|
133
132
|
line.gsub!(/\s+/, ' ')
|
134
133
|
|
135
|
-
quitting = line =~ /^\^/
|
136
|
-
line = line[1..-1] if quitting
|
137
134
|
id, days = line.split(':', 2).map(&:strip)
|
138
|
-
self.new(id, parse_days(days)
|
135
|
+
self.new(id, parse_days(days))
|
139
136
|
end
|
140
137
|
|
141
138
|
def self.parse_days(text)
|
@@ -159,6 +156,7 @@ module Quirk
|
|
159
156
|
|
160
157
|
def initialize(habits)
|
161
158
|
@habits = habits.reduce({}) {|hash,habit| hash[habit.id] = habit; hash}
|
159
|
+
@ids = habits.map(&:id)
|
162
160
|
end
|
163
161
|
|
164
162
|
def year
|
@@ -209,10 +207,6 @@ module Quirk
|
|
209
207
|
out
|
210
208
|
end
|
211
209
|
|
212
|
-
def list
|
213
|
-
@habits.values.map(&:id).sort.join("\n")
|
214
|
-
end
|
215
|
-
|
216
210
|
def mark!(line)
|
217
211
|
date = Date.parse(line.strip.split(/\s+/)[0])
|
218
212
|
originals = line.strip.split(/\s+/, 2)[1].split(',').map(&:strip)
|
@@ -231,18 +225,10 @@ module Quirk
|
|
231
225
|
end
|
232
226
|
end
|
233
227
|
|
234
|
-
def today
|
235
|
-
@habits.values.
|
236
|
-
select {|h| h.pending?(Quirk.today)}.
|
237
|
-
map(&:id).
|
238
|
-
sort.
|
239
|
-
join("\n")
|
240
|
-
end
|
241
|
-
|
242
228
|
def streaks
|
243
|
-
pairs = @
|
244
|
-
[
|
245
|
-
end
|
229
|
+
pairs = @ids.map do |id|
|
230
|
+
[@habits[id].streak, id]
|
231
|
+
end
|
246
232
|
len = pairs.map {|p| p.first.to_s.length}.max
|
247
233
|
pairs.map do |count, id|
|
248
234
|
"#{' ' * (len - count.to_s.length)}#{count} #{id}"
|
metadata
CHANGED
@@ -1,46 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quirk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.6
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Hugh Bien
|
9
8
|
autorequire:
|
10
|
-
bindir:
|
9
|
+
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-12-29 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: minitest
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: colorize
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
description: Command line tool for tracking good/bad habits, data stored in plaintext.
|
@@ -51,34 +46,31 @@ executables:
|
|
51
46
|
extensions: []
|
52
47
|
extra_rdoc_files: []
|
53
48
|
files:
|
54
|
-
- quirk.rb
|
55
|
-
- quirk_test.rb
|
56
49
|
- LICENSE.md
|
57
50
|
- README.md
|
58
|
-
- quirk
|
59
|
-
-
|
51
|
+
- bin/quirk
|
52
|
+
- lib/quirk.rb
|
60
53
|
homepage: https://github.com/hughbien/quirk
|
61
54
|
licenses: []
|
55
|
+
metadata: {}
|
62
56
|
post_install_message:
|
63
57
|
rdoc_options: []
|
64
58
|
require_paths:
|
65
59
|
- lib
|
66
60
|
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
-
none: false
|
68
61
|
requirements:
|
69
|
-
- -
|
62
|
+
- - ">="
|
70
63
|
- !ruby/object:Gem::Version
|
71
64
|
version: '0'
|
72
65
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
66
|
requirements:
|
75
|
-
- -
|
67
|
+
- - ">="
|
76
68
|
- !ruby/object:Gem::Version
|
77
69
|
version: 1.3.6
|
78
70
|
requirements: []
|
79
71
|
rubyforge_project:
|
80
|
-
rubygems_version:
|
72
|
+
rubygems_version: 2.2.2
|
81
73
|
signing_key:
|
82
|
-
specification_version:
|
74
|
+
specification_version: 4
|
83
75
|
summary: Track good and bad habits
|
84
76
|
test_files: []
|
data/quirk_test.rb
DELETED
@@ -1,206 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require "#{File.dirname(__FILE__)}/quirk"
|
3
|
-
require 'minitest/autorun'
|
4
|
-
|
5
|
-
Quirk.today = Date.new(2012, 1, 5) # 1 Su, 2 Mo, 3 Tu, 4 We, 5 Th
|
6
|
-
|
7
|
-
class QuirkAppTest < MiniTest::Unit::TestCase
|
8
|
-
def setup
|
9
|
-
@app = Quirk::App.new(File.join(File.dirname(__FILE__), 'quirkfile'))
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class QuirkHabitTest < MiniTest::Unit::TestCase
|
14
|
-
def test_parse
|
15
|
-
habit = Quirk::Habit.parse(' running: monday , tuesday, wednesday')
|
16
|
-
assert_equal('running', habit.id)
|
17
|
-
assert_equal([1, 2, 3], habit.days)
|
18
|
-
refute(habit.quitting?)
|
19
|
-
|
20
|
-
habit2 = Quirk::Habit.parse('walk-dog: everyday')
|
21
|
-
assert_equal('walk-dog', habit2.id)
|
22
|
-
assert_equal([0, 1, 2, 3, 4, 5, 6], habit2.days)
|
23
|
-
refute(habit2.quitting?)
|
24
|
-
|
25
|
-
habit3 = Quirk::Habit.parse('^quit-tv: everyday')
|
26
|
-
assert_equal('quit-tv', habit3.id)
|
27
|
-
assert_equal([0, 1, 2, 3, 4, 5, 6], habit3.days)
|
28
|
-
assert(habit3.quitting?)
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_pending
|
32
|
-
habit = Quirk::Habit.parse('running: monday')
|
33
|
-
refute(habit.pending?(Date.new(2012, 1, 1)))
|
34
|
-
assert(habit.pending?(Date.new(2012, 1, 2)))
|
35
|
-
habit.mark!(Date.new(2012, 1, 2))
|
36
|
-
refute(habit.pending?(Date.new(2012, 1, 2)))
|
37
|
-
|
38
|
-
habit2 = Quirk::Habit.parse('^quit-tv: everyday')
|
39
|
-
refute(habit.pending?(Date.new(2012, 1, 1)))
|
40
|
-
habit.mark!(Date.new(2012, 1, 1))
|
41
|
-
refute(habit.pending?(Date.new(2012, 1, 1)))
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_color_on
|
45
|
-
habit = Quirk::Habit.parse('running: sunday, monday, wednesday, thursday')
|
46
|
-
habit.mark!(Date.new(2012, 1, 2))
|
47
|
-
habit.mark!(Date.new(2012, 1, 3))
|
48
|
-
assert_equal(:white, habit.color_on(Date.new(2012, 1, 1)))
|
49
|
-
assert_equal(:light_green, habit.color_on(Date.new(2012, 1, 2)))
|
50
|
-
assert_equal(:white, habit.color_on(Date.new(2012, 1, 3)))
|
51
|
-
assert_equal(:light_red, habit.color_on(Date.new(2012, 1, 4)))
|
52
|
-
assert_equal(:white, habit.color_on(Date.new(2012, 1, 5)))
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_color_on_quit
|
56
|
-
quit = Quirk::Habit.parse('^quit-tv: sunday, monday, wednesday, thursday')
|
57
|
-
quit.mark!(Date.new(2012, 1, 2))
|
58
|
-
assert_equal(:white, quit.color_on(Date.new(2012, 1, 1)))
|
59
|
-
assert_equal(:light_red, quit.color_on(Date.new(2012, 1, 2)))
|
60
|
-
assert_equal(:white, quit.color_on(Date.new(2012, 1, 3)))
|
61
|
-
assert_equal(:light_green, quit.color_on(Date.new(2012, 1, 4)))
|
62
|
-
assert_equal(:light_green, quit.color_on(Date.new(2012, 1, 5)))
|
63
|
-
assert_equal(:white, quit.color_on(Date.new(2012, 1, 6)))
|
64
|
-
|
65
|
-
quit.mark_first!(Date.new(2012, 1, 1))
|
66
|
-
assert_equal(:light_green, quit.color_on(Date.new(2012, 1, 1)))
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_color_on_empty_quit
|
70
|
-
quit = Quirk::Habit.parse('^quit-tv: everyday')
|
71
|
-
quit.mark_first!(Date.new(2012, 1, 1))
|
72
|
-
assert_equal(:white, quit.color_on(Date.new(2011, 12, 31)))
|
73
|
-
assert_equal(:light_green, quit.color_on(Date.new(2012, 1, 1)))
|
74
|
-
assert_equal(:light_green, quit.color_on(Date.new(2012, 1, 2)))
|
75
|
-
assert_equal(:light_green, quit.color_on(Date.new(2012, 1, 3)))
|
76
|
-
assert_equal(:light_green, quit.color_on(Date.new(2012, 1, 4)))
|
77
|
-
assert_equal(:light_green, quit.color_on(Date.new(2012, 1, 5)))
|
78
|
-
assert_equal(:white, quit.color_on(Date.new(2012, 1, 6)))
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_color_on_last_date
|
82
|
-
habit = Quirk::Habit.parse('running: everyday')
|
83
|
-
habit.mark!(Date.new(2012, 1, 2))
|
84
|
-
habit.mark!(Date.new(2012, 1, 3))
|
85
|
-
habit.mark_last!(Date.new(2012, 1, 4))
|
86
|
-
assert_equal(:white, habit.color_on(Date.new(2012, 1, 1)))
|
87
|
-
assert_equal(:light_green, habit.color_on(Date.new(2012, 1, 2)))
|
88
|
-
assert_equal(:light_green, habit.color_on(Date.new(2012, 1, 3)))
|
89
|
-
assert_equal(:white, habit.color_on(Date.new(2012, 1, 4)))
|
90
|
-
assert_equal(:white, habit.color_on(Date.new(2012, 1, 5)))
|
91
|
-
|
92
|
-
habit.mark!(Date.new(2012, 1, 4))
|
93
|
-
habit.mark!(Date.new(2012, 1, 5))
|
94
|
-
assert_equal(:light_green, habit.color_on(Date.new(2012, 1, 4)))
|
95
|
-
assert_equal(:white, habit.color_on(Date.new(2012, 1, 5)))
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_color_on_future_last_date
|
99
|
-
habit = Quirk::Habit.parse('running: everyday')
|
100
|
-
habit.mark!(Date.new(2012, 1, 2))
|
101
|
-
habit.mark!(Date.new(2012, 1, 4))
|
102
|
-
habit.mark_last!(Date.new(2012, 1, 29))
|
103
|
-
assert_equal(:white, habit.color_on(Date.new(2012, 1, 1)))
|
104
|
-
assert_equal(:light_green, habit.color_on(Date.new(2012, 1, 2)))
|
105
|
-
assert_equal(:light_red, habit.color_on(Date.new(2012, 1, 3)))
|
106
|
-
assert_equal(:light_green, habit.color_on(Date.new(2012, 1, 4)))
|
107
|
-
assert_equal(:white, habit.color_on(Date.new(2012, 1, 5)))
|
108
|
-
assert_equal(:white, habit.color_on(Date.new(2012, 1, 6)))
|
109
|
-
assert_equal(:white, habit.color_on(Date.new(2012, 1, 28)))
|
110
|
-
assert_equal(:white, habit.color_on(Date.new(2012, 1, 29)))
|
111
|
-
assert_equal(:white, habit.color_on(Date.new(2012, 1, 30)))
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_color_on_quit_last_date
|
115
|
-
quit = Quirk::Habit.parse('^quit-tv: everyday')
|
116
|
-
quit.mark_first!(Date.new(2012, 1, 1))
|
117
|
-
quit.mark_last!(Date.new(2012, 1, 4))
|
118
|
-
quit.mark!(Date.new(2012, 1, 5))
|
119
|
-
assert_equal(:light_green, quit.color_on(Date.new(2012, 1, 1)))
|
120
|
-
assert_equal(:light_green, quit.color_on(Date.new(2012, 1, 2)))
|
121
|
-
assert_equal(:light_green, quit.color_on(Date.new(2012, 1, 3)))
|
122
|
-
assert_equal(:light_green, quit.color_on(Date.new(2012, 1, 4)))
|
123
|
-
assert_equal(:white, quit.color_on(Date.new(2012, 1, 5)))
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_streak
|
127
|
-
missing = Quirk::Habit.parse('running: everyday')
|
128
|
-
assert_equal(0, missing.streak)
|
129
|
-
|
130
|
-
perfect = Quirk::Habit.parse('running: monday, wednesday')
|
131
|
-
perfect.mark!(Date.new(2012, 1, 2))
|
132
|
-
perfect.mark!(Date.new(2012, 1, 4))
|
133
|
-
assert_equal(2, perfect.streak)
|
134
|
-
|
135
|
-
bad = Quirk::Habit.parse('running: monday, tuesday, wednesday')
|
136
|
-
bad.mark!(Date.new(2012, 1, 1))
|
137
|
-
bad.mark!(Date.new(2012, 1, 2))
|
138
|
-
assert_equal(-2, bad.streak)
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_streak_quit
|
142
|
-
missing = Quirk::Habit.parse('^quit-tv: everyday')
|
143
|
-
assert_equal(0, missing.streak)
|
144
|
-
|
145
|
-
perfect = Quirk::Habit.parse('^quit-tv: monday, tuesday')
|
146
|
-
perfect.mark!(Date.new(2011, 12, 31))
|
147
|
-
perfect.mark!(Date.new(2012, 1, 4))
|
148
|
-
assert_equal(2, perfect.streak)
|
149
|
-
|
150
|
-
bad = Quirk::Habit.parse('^quit-tv: sunday, thursday')
|
151
|
-
bad.mark!(Date.new(2012, 1, 1)) # sunday
|
152
|
-
bad.mark!(Date.new(2012, 1, 5)) # thursday
|
153
|
-
assert_equal(-2, bad.streak)
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
class QuirkCalendarTest < MiniTest::Unit::TestCase
|
158
|
-
def setup
|
159
|
-
@running = Quirk::Habit.parse('running: everyday')
|
160
|
-
@walking = Quirk::Habit.parse('walk-dog: sunday, saturday')
|
161
|
-
@smoking = Quirk::Habit.parse('^smoking: everyday')
|
162
|
-
@cal = Quirk::Calendar.new([@running, @walking, @smoking])
|
163
|
-
@cal.mark!('2012/01/01 ^smoking')
|
164
|
-
@cal.mark!('2012/01/04 $smoking')
|
165
|
-
@cal.mark!('2012/01/01 running, walk-dog')
|
166
|
-
@cal.mark!('2012/01/02 running, walk-dog')
|
167
|
-
end
|
168
|
-
|
169
|
-
def test_parse
|
170
|
-
calendar = Quirk::Calendar.parse(
|
171
|
-
"; ignore comment line\n" +
|
172
|
-
"running: everyday ; ignore comment\n" +
|
173
|
-
"^smoking: everyday\n\n" +
|
174
|
-
"; ignore comment line\n" +
|
175
|
-
"2012/01/01 ^smoking ; ignore comment\n" +
|
176
|
-
"2012/01/01 running\n\n")
|
177
|
-
|
178
|
-
assert(calendar.has_habit?('running'))
|
179
|
-
assert(calendar.has_habit?('smoking'))
|
180
|
-
assert_equal(Date.new(2012, 1, 1), calendar.habits['running'].first_date)
|
181
|
-
assert_equal(Date.new(2012, 1, 1), calendar.habits['smoking'].first_date)
|
182
|
-
end
|
183
|
-
|
184
|
-
def test_parse_day_error
|
185
|
-
assert_raises(RuntimeError) { Quirk::Calendar.parse('running: invalid') }
|
186
|
-
end
|
187
|
-
|
188
|
-
def test_mark
|
189
|
-
assert_equal([Date.new(2012,1,1), Date.new(2012,1,2)], @running.marks)
|
190
|
-
assert_equal([Date.new(2012,1,1), Date.new(2012,1,2)], @walking.marks)
|
191
|
-
end
|
192
|
-
|
193
|
-
def test_mark_first
|
194
|
-
assert_equal(Date.new(2012, 1, 1), @smoking.first_date)
|
195
|
-
end
|
196
|
-
|
197
|
-
def test_today
|
198
|
-
assert_equal("running", @cal.today)
|
199
|
-
@cal.mark!('2012/01/05 running')
|
200
|
-
assert_equal("", @cal.today)
|
201
|
-
end
|
202
|
-
|
203
|
-
def test_streaks
|
204
|
-
assert_equal("-2 running\n 1 walk-dog\n 4 smoking", @cal.streaks)
|
205
|
-
end
|
206
|
-
end
|