habits 0.1 → 0.1.1

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.
@@ -48,7 +48,8 @@ sub.register('list', [], 'List habits.') do
48
48
  puts "\nOn Hold: #{on_hold.map{|h| h.title}.join(', ')}.\n"
49
49
  end
50
50
 
51
- puts "\nWeek #{Date.today.cweek} | Total #{Habits::Habit.all.size} habits.\n\n"
51
+ puts "\nWeek #{Date.today.cweek} | Total #{Habits::Habit.all.size} habits "+
52
+ "| #{Habits::Habit.missed_count} missed\n\n"
52
53
  end
53
54
 
54
55
  sub.register('zones', ['TITLE','YELLOW_ZONE','RED_ZONE'],
data/lib/habits/habit.rb CHANGED
@@ -11,6 +11,7 @@ module Habits
11
11
  HABITS_DIR = File.join(ENV['HOME'], '.habits')
12
12
  YELLOW_ZONE = 16*60*60 # 16 hours before deadline,
13
13
  RED_ZONE = 6*60*60 # 6 -"-
14
+ DAYS = Time::RFC2822_DAY_NAME
14
15
 
15
16
  def self.all
16
17
  @@all ||= begin
@@ -30,6 +31,10 @@ module Habits
30
31
  all.select{|habit| habit.status == Status.on_hold}
31
32
  end
32
33
 
34
+ def self.missed_count
35
+ all.select{|habit| habit.status == Status.missed}.size
36
+ end
37
+
33
38
  def self.find(title)
34
39
  h = Habit.all.detect {|h| h.title == title.strip}
35
40
  raise "No such habit found." unless h
@@ -112,8 +117,8 @@ module Habits
112
117
  end
113
118
 
114
119
  def set_days(days)
115
- if days.detect{|d| Time::RFC2822_DAY_NAME.index(d).nil?}
116
- raise "Valid days are #{Time::RFC2822_DAY_NAME.join(',')}"
120
+ if days.detect{|d| DAYS.index(d).nil?}
121
+ raise "Valid days are #{DAYS.join(',')}"
117
122
  else
118
123
  @days = days
119
124
  end
@@ -137,7 +142,7 @@ module Habits
137
142
  @events += habit.events
138
143
  @days += habit.days
139
144
  @days.uniq!
140
- @days.sort!{|a,b| Time::RFC2822_DAY_NAME.index(a) <=> Time::RFC2822_DAY_NAME.index(b)}
145
+ @days.sort!{|a,b| DAYS.index(a) <=> DAYS.index(b)}
141
146
  end
142
147
 
143
148
  def join!(habit)
data/lib/habits/status.rb CHANGED
@@ -31,9 +31,10 @@ module Habits
31
31
 
32
32
  habit.days.each do |day|
33
33
  activities = habit.activities_on_week(date.cweek, day)
34
- day_diff = Time::RFC2822_DAY_NAME.index(day) - date.wday
34
+ day_diff = Habit::DAYS.index(day) - date.wday
35
+ day_diff -= 7 if day_diff > 0
35
36
 
36
- if !activities.empty? or (day_diff > 0)
37
+ if !activities.empty?
37
38
  statuses << Status.green
38
39
  else
39
40
  dl_date = date + day_diff
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: habits
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- version: "0.1"
9
+ - 1
10
+ version: 0.1.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Antti Hakala
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-11-26 00:00:00 +02:00
18
+ date: 2010-12-13 00:00:00 +02:00
18
19
  default_executable:
19
20
  dependencies: []
20
21