active_recall 1.8.4 → 1.8.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d38e08a2f83ec8a0b36852b6d7e10ab4798debfaa8d51f5f4f7c29f7467a1e78
4
- data.tar.gz: a41ee1c1b84ea9d8d5aa4c7fe51a0151bac1a54f7baea5e1b5f655b7daba304b
3
+ metadata.gz: 95111c003ae9481ad46fd817553888897dcbcab55e901240bb76169dc60c56ff
4
+ data.tar.gz: 71c3da4109511587c2adbc2056d8ddd12f18e5c0bfa263b38c3e1516b667c8a0
5
5
  SHA512:
6
- metadata.gz: e3afc2c4dbf422117dbdcaef6b38389f26553c4726513fc4785fafa7a07a3a79f9e01f7c2f0daca4564feba60098290cddf2e1d742a370b27ead1dd2b618f8be
7
- data.tar.gz: 12808e551f259b31bfca025753855c764bd0a67dfe13a470122fe72e3f8544cac05a00d53d4c91a5f17aa4d4014a6e19eceb02f7c10b2e96adc6e37e7440ae8d
6
+ metadata.gz: 4a93d9af15d20ecaf631a7ebf9ae36568849c103f916e80b4d4bd0782563420b1280aca3fa951ad622ec30b1e6d6a509966b5ffa92ef940c75928c175a05dd46
7
+ data.tar.gz: dd1119b28d07cf45db8177ffba1b7486e5b623d8472c2f7decb1549391d9258c9924c6b22b5285647b3c1fecc26e1f8cc2980ca73615c9e37356cc22d6b72e37
data/.gitignore CHANGED
@@ -14,3 +14,4 @@ spec/reports
14
14
  test/tmp
15
15
  test/version_tmp
16
16
  tmp
17
+ .idea/
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_recall (1.8.4)
4
+ active_recall (1.8.6)
5
5
  activerecord (>= 5.2.3, <= 7.1)
6
6
  activesupport (>= 5.2.3, <= 7.1)
7
7
 
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,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "active_recall"
5
+
6
+ # You can add here some code to start an interactive console or debug session.
7
+ # `binding.pry` from the Pry gem is often used for this purpose.
8
+ require "irb"
9
+ IRB.start(__FILE__)
@@ -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
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_record"
4
+ require "active_support/concern"
5
+
3
6
  module ActiveRecall
4
7
  module Base
5
8
  extend ActiveSupport::Concern
@@ -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.each do |item|
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
- raise ArgumentError, "Word already in the stack" if include?(source)
20
+ attributes = {deck: self, source_id: source.id, source_type: source.class.name}
31
21
 
32
- items << ActiveRecall::Item.new(deck: self, source_id: source.id, source_type: source.class.name)
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.find(items.where(box: number).pluck(:source_id))
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecall
4
- VERSION = "1.8.4"
4
+ VERSION = "1.8.6"
5
5
  end
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
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-06-30 00:00:00.000000000 Z
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