forgetful 0.3.3 → 0.4.0
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/VERSION +1 -1
- data/bin/forgetful +37 -7
- data/lib/forgetful/cli.rb +5 -5
- data/lib/forgetful/csv_ext/reminder.rb +4 -3
- metadata +6 -7
- data/.gitignore +0 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/bin/forgetful
CHANGED
@@ -6,34 +6,64 @@ require 'optparse'
|
|
6
6
|
|
7
7
|
#-------------------------------------------------
|
8
8
|
|
9
|
+
class FormatException < RuntimeError; end
|
10
|
+
|
11
|
+
#-------------------------------------------------
|
12
|
+
|
13
|
+
def parse_range(value)
|
14
|
+
case value
|
15
|
+
when /\A(\d+)\Z/
|
16
|
+
min = 0
|
17
|
+
max = Integer($1)
|
18
|
+
when /\A(\d+)\.\.(\d+)\Z/
|
19
|
+
min = Integer($1)
|
20
|
+
max = Integer($2)
|
21
|
+
else
|
22
|
+
raise FormatException.new("unrecognized format: '#{value}'")
|
23
|
+
end
|
24
|
+
|
25
|
+
raise FormatException.new("min cannot be larger than max: '#{value}'") if min > max
|
26
|
+
|
27
|
+
min..max
|
28
|
+
end
|
29
|
+
|
9
30
|
def parse(args)
|
10
31
|
options = { :filenames => [],
|
11
32
|
:verbose => false,
|
12
|
-
:action => :quiz
|
33
|
+
:action => :quiz,
|
34
|
+
:delay => 0..0 }
|
13
35
|
|
14
36
|
args.options do |arg|
|
15
37
|
arg.banner = "Usage: forgetful [OPTION]... [FILE]..."
|
16
38
|
arg.separator ""
|
17
39
|
arg.separator "Specific options:"
|
18
40
|
|
19
|
-
arg.on( '-t', '--touch',
|
41
|
+
arg.on( '-t', '--touch', "Validate filename(s) and write back in full CSV format") do
|
20
42
|
options[:action] = :touch
|
21
43
|
end
|
22
44
|
|
45
|
+
arg.on( '-d', '--delay VALUE', "Delay range (in days) to add to unscheduled items (used with --touch)") do |value|
|
46
|
+
begin
|
47
|
+
options[:delay] = parse_range(value)
|
48
|
+
rescue FormatException => e
|
49
|
+
arg.abort(e.message)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
23
53
|
arg.separator ""
|
24
54
|
arg.separator "Common options:"
|
25
55
|
|
26
|
-
arg.on( '-v', '--verbose',
|
56
|
+
arg.on( '-v', '--verbose', "Show more information") do
|
27
57
|
options[:verbose] = true
|
28
58
|
end
|
29
59
|
|
30
|
-
arg.on( '--version',
|
60
|
+
arg.on( '--version', "Show version") do
|
31
61
|
puts File.read(File.join(File.dirname(__FILE__), "..", "VERSION"))
|
32
62
|
exit
|
33
63
|
end
|
34
64
|
|
35
|
-
arg.on_tail('-h', '--help',
|
36
|
-
|
65
|
+
arg.on_tail('-h', '--help', "Show this message") do
|
66
|
+
warn(arg)
|
37
67
|
exit
|
38
68
|
end
|
39
69
|
|
@@ -52,7 +82,7 @@ options = parse(ARGV)
|
|
52
82
|
|
53
83
|
begin
|
54
84
|
options[:filenames].each do |filename|
|
55
|
-
ReminderFile.new(filename, options[:verbose]).send(options[:action])
|
85
|
+
ReminderFile.new(filename, options[:verbose], options[:delay]).send(options[:action])
|
56
86
|
end
|
57
87
|
rescue Interrupt
|
58
88
|
puts
|
data/lib/forgetful/cli.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
|
2
2
|
class ReminderFile
|
3
|
-
attr_reader :filename, :verbose
|
3
|
+
attr_reader :filename, :verbose, :delay
|
4
4
|
|
5
|
-
def initialize(filename, verbose=false)
|
5
|
+
def initialize(filename, verbose=false, delay=0..0)
|
6
6
|
@filename = filename
|
7
7
|
@verbose = verbose
|
8
|
+
@delay = delay
|
8
9
|
end
|
9
10
|
|
10
11
|
def reminders
|
11
|
-
@reminders ||= Reminder.read_csv(filename)
|
12
|
+
@reminders ||= Reminder.read_csv(filename, delay)
|
12
13
|
end
|
13
14
|
|
14
15
|
def write(reminders)
|
15
16
|
raise "Writing back a different number of reminders than read from file (#{reminders.size} != #{@reminders.size})" if reminders.size != @reminders.size
|
16
|
-
Reminder.write_csv(filename, reminders
|
17
|
+
Reminder.write_csv(filename, reminders)
|
17
18
|
end
|
18
19
|
|
19
20
|
# subtle -- reading and writing back a file will:
|
20
21
|
# 1. validate the file
|
21
22
|
# 2. add the date column
|
22
|
-
# 3. sort the rows
|
23
23
|
def touch
|
24
24
|
puts "### TOUCH: #{filename}"
|
25
25
|
write(reminders)
|
@@ -16,13 +16,13 @@ class Reminder
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
def self.read_csv(filename)
|
19
|
+
def self.read_csv(filename, delay=0..0)
|
20
20
|
File.open(filename) do |file|
|
21
|
-
self.parse_csv(file)
|
21
|
+
self.parse_csv(file, delay)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def self.parse_csv(io)
|
25
|
+
def self.parse_csv(io, delay=0..0)
|
26
26
|
converters = [lambda { |question| question },
|
27
27
|
lambda { |answer| answer },
|
28
28
|
lambda { |due_on| Date.parse(due_on) },
|
@@ -30,6 +30,7 @@ class Reminder
|
|
30
30
|
|
31
31
|
CSV.parse(io, :skip_blanks => true).map do |list|
|
32
32
|
list = list.zip(converters).map { |col, converter| converter[col] }
|
33
|
+
list << Date.today + Random.new.rand(delay) if list.length == 2 # missing date
|
33
34
|
new(*list)
|
34
35
|
end
|
35
36
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 4
|
8
|
+
- 0
|
9
|
+
version: 0.4.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jonathan Palardy
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2011-04-19 00:00:00 -04:00
|
18
18
|
default_executable: forgetful
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -42,7 +42,6 @@ extra_rdoc_files:
|
|
42
42
|
- LICENSE
|
43
43
|
- README.rdoc
|
44
44
|
files:
|
45
|
-
- .gitignore
|
46
45
|
- LICENSE
|
47
46
|
- README.rdoc
|
48
47
|
- Rakefile
|
@@ -65,8 +64,8 @@ homepage: http://github.com/jpalardy/forgetful
|
|
65
64
|
licenses: []
|
66
65
|
|
67
66
|
post_install_message:
|
68
|
-
rdoc_options:
|
69
|
-
|
67
|
+
rdoc_options: []
|
68
|
+
|
70
69
|
require_paths:
|
71
70
|
- lib
|
72
71
|
required_ruby_version: !ruby/object:Gem::Requirement
|
data/.gitignore
DELETED