forgetful 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/bin/forgetful
CHANGED
@@ -1,76 +1,58 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
############################################################
|
4
1
|
|
5
2
|
require "forgetful"
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def ask(prompt, validate_re=//)
|
10
|
-
while true
|
11
|
-
print prompt
|
12
|
-
answer = readline.chomp
|
13
|
-
|
14
|
-
return answer.to_i if answer =~ validate_re
|
15
|
-
end
|
16
|
-
end
|
3
|
+
require "forgetful/cli"
|
4
|
+
require 'getoptlong'
|
17
5
|
|
18
6
|
#-------------------------------------------------
|
19
7
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
8
|
+
def usage(status=0)
|
9
|
+
$stderr.puts <<-END
|
10
|
+
Usage: #{File.basename($0)} [options] filename(s)
|
23
11
|
|
24
|
-
|
12
|
+
--help, -h Show this message
|
13
|
+
--touch, -t Validate filename(s) and write back in full CSV format
|
14
|
+
--version Show version information
|
15
|
+
END
|
25
16
|
|
26
|
-
|
27
|
-
width = "#{n}/#{n}. ".size
|
28
|
-
padding = " " * width
|
29
|
-
ask "#{i}/#{n}. ".rjust(width) + "Q: #{reminder.question}"
|
30
|
-
puts padding + "A: #{reminder.answer}"
|
31
|
-
q = ask_grade padding + "? "
|
32
|
-
puts
|
33
|
-
return q
|
17
|
+
exit status
|
34
18
|
end
|
35
19
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
20
|
+
def parse_argv
|
21
|
+
result = { :filenames => [],
|
22
|
+
:action => :quiz }
|
23
|
+
|
24
|
+
opts = GetoptLong.new(['--help', '-h', GetoptLong::NO_ARGUMENT],
|
25
|
+
['--touch', '-t', GetoptLong::NO_ARGUMENT],
|
26
|
+
['--version', GetoptLong::NO_ARGUMENT])
|
27
|
+
|
28
|
+
opts.each do |opt, arg|
|
29
|
+
case opt
|
30
|
+
when '--help'
|
31
|
+
usage
|
32
|
+
when '--touch'
|
33
|
+
result[:action] = :touch
|
34
|
+
when '--version'
|
35
|
+
puts File.read(File.join(File.dirname(__FILE__), "..", "VERSION"))
|
36
|
+
exit 0
|
37
|
+
end
|
43
38
|
end
|
44
|
-
end
|
45
|
-
|
46
|
-
############################################################
|
47
|
-
|
48
|
-
def process_file(filename)
|
49
|
-
#--------------------- quiz ----------------------
|
50
|
-
reminders = Reminder.read_csv(filename)
|
51
|
-
|
52
|
-
dues, not_dues = reminders.partition {|reminder| reminder.due_on <= Date.today}
|
53
39
|
|
54
|
-
|
55
|
-
|
40
|
+
result[:filenames] = ARGV.dup
|
41
|
+
ARGV.clear
|
56
42
|
|
57
|
-
|
58
|
-
|
59
|
-
#-------------------- review ---------------------
|
60
|
-
faileds = gradeds.select {|reminder| reminder.review? }
|
61
|
-
until faileds.empty?
|
62
|
-
puts "# REVIEW: #{filename}"
|
63
|
-
gradeds = quiz(faileds.sort_by { rand }) # review
|
64
|
-
faileds = gradeds.select {|reminder| reminder.review? }
|
65
|
-
end
|
43
|
+
result
|
66
44
|
end
|
67
45
|
|
68
|
-
|
46
|
+
#-------------------------------------------------
|
69
47
|
|
70
|
-
|
71
|
-
ARGV.clear
|
48
|
+
options = parse_argv
|
72
49
|
|
73
|
-
|
74
|
-
|
50
|
+
begin
|
51
|
+
options[:filenames].each do |filename|
|
52
|
+
ReminderFile.new(filename).send(options[:action])
|
53
|
+
end
|
54
|
+
rescue Interrupt
|
55
|
+
puts
|
56
|
+
# aborting ... won't save file
|
75
57
|
end
|
76
58
|
|
File without changes
|
File without changes
|
@@ -0,0 +1,68 @@
|
|
1
|
+
|
2
|
+
class ReminderFile
|
3
|
+
attr_reader :filename
|
4
|
+
|
5
|
+
def initialize(filename)
|
6
|
+
@filename = filename
|
7
|
+
end
|
8
|
+
|
9
|
+
def reminders
|
10
|
+
@reminders ||= Reminder.read_csv(filename)
|
11
|
+
end
|
12
|
+
|
13
|
+
def reminders=(reminders)
|
14
|
+
Reminder.write_csv(filename, reminders.sort)
|
15
|
+
end
|
16
|
+
|
17
|
+
# subtle -- reading and writing back a file will:
|
18
|
+
# 1. validate the file
|
19
|
+
# 2. add the date column
|
20
|
+
# 3. sort the rows
|
21
|
+
def touch
|
22
|
+
puts "### TOUCH: #{filename}"
|
23
|
+
self.reminders = reminders
|
24
|
+
end
|
25
|
+
|
26
|
+
def quiz
|
27
|
+
puts "### QUIZ: #{filename}"
|
28
|
+
dues, not_dues = reminders.partition { |reminder| reminder.due_on <= Date.today }
|
29
|
+
gradeds = quiz_map(dues.sort_by { rand })
|
30
|
+
|
31
|
+
self.reminders = gradeds + not_dues
|
32
|
+
|
33
|
+
faileds = gradeds.select { |reminder| reminder.review? }
|
34
|
+
until faileds.empty?
|
35
|
+
puts "### REVIEW: #{filename}"
|
36
|
+
gradeds = quiz_map(faileds.sort_by { rand })
|
37
|
+
faileds = gradeds.select { |reminder| reminder.review? }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def quiz_map(reminders)
|
43
|
+
reminders.zip(1..reminders.length).map do |reminder, i|
|
44
|
+
q = ask(reminder, i, reminders.size)
|
45
|
+
reminder.next(q)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def ask(reminder, i, n)
|
50
|
+
width = "#{n}/#{n}. ".size
|
51
|
+
padding = " " * width
|
52
|
+
|
53
|
+
print "#{i}/#{n}. ".rjust(width) + "Q: #{reminder.question}"
|
54
|
+
readline
|
55
|
+
|
56
|
+
puts padding + "A: #{reminder.answer}"
|
57
|
+
|
58
|
+
while true
|
59
|
+
print padding + "? "
|
60
|
+
answer = readline.chomp
|
61
|
+
|
62
|
+
if answer =~ /\A[0-5]\Z/
|
63
|
+
puts
|
64
|
+
return answer.to_i
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
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
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.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: 2010-
|
17
|
+
date: 2010-06-22 00:00:00 -04:00
|
18
18
|
default_executable: forgetful
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -48,9 +48,10 @@ files:
|
|
48
48
|
- Rakefile
|
49
49
|
- VERSION
|
50
50
|
- bin/forgetful
|
51
|
-
- examples/
|
52
|
-
- examples/
|
51
|
+
- examples/katakana_romaji.csv
|
52
|
+
- examples/romaji_katakana.csv
|
53
53
|
- lib/forgetful.rb
|
54
|
+
- lib/forgetful/cli.rb
|
54
55
|
- lib/forgetful/csv_ext/reminder.rb
|
55
56
|
- lib/forgetful/reminder.rb
|
56
57
|
- lib/forgetful/supermemo.rb
|