active_recall 1.8.4 → 1.8.6
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -0
- data/bin/console +9 -0
- data/lib/active_recall/algorithms/soft_leitner_system.rb +65 -0
- data/lib/active_recall/base.rb +3 -0
- data/lib/active_recall/models/deck.rb +12 -14
- data/lib/active_recall/version.rb +1 -1
- data/lib/active_recall.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 95111c003ae9481ad46fd817553888897dcbcab55e901240bb76169dc60c56ff
|
|
4
|
+
data.tar.gz: 71c3da4109511587c2adbc2056d8ddd12f18e5c0bfa263b38c3e1516b667c8a0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4a93d9af15d20ecaf631a7ebf9ae36568849c103f916e80b4d4bd0782563420b1280aca3fa951ad622ec30b1e6d6a509966b5ffa92ef940c75928c175a05dd46
|
|
7
|
+
data.tar.gz: dd1119b28d07cf45db8177ffba1b7486e5b623d8472c2f7decb1549391d9258c9924c6b22b5285647b3c1fecc26e1f8cc2980ca73615c9e37356cc22d6b72e37
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -35,6 +35,7 @@ ActiveRecall.configure do |config|
|
|
|
35
35
|
config.algorithm_class = ActiveRecall::FibonacciSequence
|
|
36
36
|
end
|
|
37
37
|
```
|
|
38
|
+
Algorithms include `FibonacciSequence`, `LeitnerSystem`, and `SoftLeitnerSystem`.
|
|
38
39
|
For Rails applications, try doing this from within an [initializer file](https://guides.rubyonrails.org/configuring.html#using-initializer-files).
|
|
39
40
|
|
|
40
41
|
Assume you have an application allowing your users to study words in a foreign language. Using the `has_deck` method you can set up a deck of flashcards that the user will study:
|
data/bin/console
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ActiveRecall
|
|
4
|
+
class SoftLeitnerSystem
|
|
5
|
+
DELAYS = [3, 7, 14, 30, 60, 120, 240].freeze
|
|
6
|
+
|
|
7
|
+
def self.right(box:, times_right:, times_wrong:, current_time: Time.current)
|
|
8
|
+
new(
|
|
9
|
+
box: box,
|
|
10
|
+
current_time: current_time,
|
|
11
|
+
times_right: times_right,
|
|
12
|
+
times_wrong: times_wrong
|
|
13
|
+
).right
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.wrong(box:, times_right:, times_wrong:, current_time: Time.current)
|
|
17
|
+
new(
|
|
18
|
+
box: box,
|
|
19
|
+
current_time: current_time,
|
|
20
|
+
times_right: times_right,
|
|
21
|
+
times_wrong: times_wrong
|
|
22
|
+
).wrong
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def initialize(box:, times_right:, times_wrong:, current_time: Time.current)
|
|
26
|
+
@box = box
|
|
27
|
+
@current_time = current_time
|
|
28
|
+
@times_right = times_right
|
|
29
|
+
@times_wrong = times_wrong
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def right
|
|
33
|
+
self.box = [box + 1, DELAYS.count].min
|
|
34
|
+
|
|
35
|
+
{
|
|
36
|
+
box: box,
|
|
37
|
+
times_right: times_right + 1,
|
|
38
|
+
times_wrong: times_wrong,
|
|
39
|
+
last_reviewed: current_time,
|
|
40
|
+
next_review: next_review
|
|
41
|
+
}
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def wrong
|
|
45
|
+
self.box = [box - 1, 0].max
|
|
46
|
+
|
|
47
|
+
{
|
|
48
|
+
box: box,
|
|
49
|
+
times_right: times_right,
|
|
50
|
+
times_wrong: times_wrong + 1,
|
|
51
|
+
last_reviewed: current_time,
|
|
52
|
+
next_review: next_review
|
|
53
|
+
}
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
attr_accessor :box
|
|
59
|
+
attr_reader :current_time, :times_right, :times_wrong
|
|
60
|
+
|
|
61
|
+
def next_review
|
|
62
|
+
(current_time + DELAYS[[DELAYS.count, box].min - 1].days)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
data/lib/active_recall/base.rb
CHANGED
|
@@ -9,27 +9,21 @@ module ActiveRecall
|
|
|
9
9
|
has_many :items, class_name: "ActiveRecall::Item", dependent: :destroy
|
|
10
10
|
|
|
11
11
|
def each
|
|
12
|
-
_items.
|
|
13
|
-
if block_given?
|
|
14
|
-
yield item
|
|
15
|
-
else
|
|
16
|
-
yield item
|
|
17
|
-
end
|
|
18
|
-
end
|
|
12
|
+
_items.find_each { |item| yield item }
|
|
19
13
|
end
|
|
20
14
|
|
|
21
15
|
def ==(other)
|
|
22
16
|
_items == other
|
|
23
17
|
end
|
|
24
18
|
|
|
25
|
-
def _items
|
|
26
|
-
source_class.find(items.pluck(:source_id))
|
|
27
|
-
end
|
|
28
|
-
|
|
29
19
|
def <<(source)
|
|
30
|
-
|
|
20
|
+
attributes = {deck: self, source_id: source.id, source_type: source.class.name}
|
|
31
21
|
|
|
32
|
-
|
|
22
|
+
if ActiveRecall::Item.exists?(attributes)
|
|
23
|
+
raise ArgumentError, "Word already in the stack"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
items << ActiveRecall::Item.new(attributes)
|
|
33
27
|
end
|
|
34
28
|
|
|
35
29
|
def self.add_deck(user)
|
|
@@ -71,7 +65,7 @@ module ActiveRecall
|
|
|
71
65
|
end
|
|
72
66
|
|
|
73
67
|
def box(number)
|
|
74
|
-
source_class.
|
|
68
|
+
source_class.where(id: items.where(box: number).select(:source_id))
|
|
75
69
|
end
|
|
76
70
|
|
|
77
71
|
def source_class
|
|
@@ -80,6 +74,10 @@ module ActiveRecall
|
|
|
80
74
|
|
|
81
75
|
private
|
|
82
76
|
|
|
77
|
+
def _items
|
|
78
|
+
source_class.where(id: items.select(:source_id))
|
|
79
|
+
end
|
|
80
|
+
|
|
83
81
|
def _review
|
|
84
82
|
items
|
|
85
83
|
.untested
|
data/lib/active_recall.rb
CHANGED
|
@@ -5,6 +5,7 @@ require "active_recall/deck_methods"
|
|
|
5
5
|
require "active_recall/item_methods"
|
|
6
6
|
require "active_recall/algorithms/fibonacci_sequence"
|
|
7
7
|
require "active_recall/algorithms/leitner_system"
|
|
8
|
+
require "active_recall/algorithms/soft_leitner_system"
|
|
8
9
|
require "active_recall/configuration"
|
|
9
10
|
require "active_recall/models/deck"
|
|
10
11
|
require "active_recall/models/item"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: active_recall
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.8.
|
|
4
|
+
version: 1.8.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Robert Gravina
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: exe
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2023-
|
|
12
|
+
date: 2023-09-11 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rake
|
|
@@ -125,10 +125,12 @@ files:
|
|
|
125
125
|
- README.md
|
|
126
126
|
- Rakefile
|
|
127
127
|
- active_recall.gemspec
|
|
128
|
+
- bin/console
|
|
128
129
|
- bin/setup
|
|
129
130
|
- lib/active_recall.rb
|
|
130
131
|
- lib/active_recall/algorithms/fibonacci_sequence.rb
|
|
131
132
|
- lib/active_recall/algorithms/leitner_system.rb
|
|
133
|
+
- lib/active_recall/algorithms/soft_leitner_system.rb
|
|
132
134
|
- lib/active_recall/base.rb
|
|
133
135
|
- lib/active_recall/configuration.rb
|
|
134
136
|
- lib/active_recall/deck_methods.rb
|