repetition 1.0.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +5 -0
- data/CHANGELOG.md +25 -0
- data/Gemfile +2 -0
- data/LICENSE.TXT +21 -0
- data/README.md +25 -52
- data/Rakefile +8 -4
- data/bin/console +4 -4
- data/lib/repetition.rb +48 -37
- data/lib/repetition/version.rb +1 -1
- data/repetition.gemspec +13 -14
- metadata +14 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 395411bf8918658d462f941a292cf0ed689987505f30c13e31843fad1e45e38a
|
4
|
+
data.tar.gz: bc4232618f5ebde02ee0b6c63daf4b21217a43bb9aa29a8230279f374bd9d67c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0b276d0d13d1515c656b967a397ad89bcf50925c66920a7f1daf65eda1ef8136b021e44ed6751b748dc2da4b9db7a9fa8d0a2037cc3f578a431729448ab8276
|
7
|
+
data.tar.gz: e1bb3c765debf1b8b1acafdb75e9477581d36d9ba4d062c408d1e31d63a164088798cf9a9c76a740fb89fab9fb7382bc75198c12c8219b9331cc560962d4f7a7
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
|
+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [Unreleased]
|
8
|
+
|
9
|
+
## [2.0.0] - 2018-08-08
|
10
|
+
### Changed
|
11
|
+
- Move from module to class implementation
|
12
|
+
- Test with Minitest instead of RSpec
|
13
|
+
|
14
|
+
## [1.0.1] - 2017-04-10
|
15
|
+
### Changed
|
16
|
+
- Move code into a Bundler style gem package
|
17
|
+
- Update gemspec
|
18
|
+
- Update dependencies
|
19
|
+
|
20
|
+
### Fixed
|
21
|
+
- Require date for non-Rails projects
|
22
|
+
|
23
|
+
## [1.0.0] - 2014-06-14
|
24
|
+
### Added
|
25
|
+
- Initial release
|
data/Gemfile
CHANGED
data/LICENSE.TXT
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Dan Kim
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,70 +1,43 @@
|
|
1
|
-
# Repetition
|
2
|
-
Spaced repetition module which can be used as a mixin in Ruby apps. SuperMemo 2 is used as a repetition algorithm.
|
3
|
-
|
4
|
-
### Installation
|
5
|
-
Add to your Gemfile
|
6
|
-
|
7
|
-
gem 'repetition'
|
1
|
+
# Repetition
|
8
2
|
|
9
|
-
|
10
|
-
|
11
|
-
gem install repetition
|
3
|
+
Spaced repetition module which can be used as a mixin in Ruby apps. SuperMemo 2 is used as a repetition algorithm.
|
12
4
|
|
5
|
+
## Installation
|
13
6
|
|
14
|
-
|
7
|
+
Add this line to your application's Gemfile:
|
15
8
|
|
16
|
-
Create a migration to add the new fields to your model.
|
17
9
|
```ruby
|
18
|
-
|
19
|
-
t.decimal :easiness_factor, precision: 2, scale: 1, default: 2.5, null: false
|
20
|
-
t.integer :number_repetitions, default: 0, null: false
|
21
|
-
t.integer :quality_of_last_recall
|
22
|
-
t.date :next_repetition
|
23
|
-
t.integer :repetition_interval
|
24
|
-
t.date :last_studied
|
25
|
-
end
|
10
|
+
gem 'repetition'
|
26
11
|
```
|
27
12
|
|
28
|
-
|
29
|
-
Include module in your class or ActiveRecord model
|
30
|
-
```ruby
|
31
|
-
class Card < ActiveRecord::Base
|
32
|
-
# some code
|
33
|
-
include Repetition
|
34
|
-
end
|
35
|
-
```
|
13
|
+
And then execute:
|
36
14
|
|
37
|
-
|
38
|
-
* easyness_factor
|
39
|
-
* number_repetitions
|
40
|
-
* quality_of_last_recall
|
41
|
-
* next_repetition
|
42
|
-
* repetition_interval
|
43
|
-
* last_studied
|
15
|
+
$ bundle
|
44
16
|
|
45
|
-
|
17
|
+
Or install it yourself as:
|
46
18
|
|
47
|
-
|
48
|
-
```ruby
|
49
|
-
card = Card.first
|
50
|
-
card.reset_spaced_repetition_data # Reset data for first use
|
19
|
+
$ gem install repetition
|
51
20
|
|
52
|
-
|
53
|
-
card.process_recall_result(4)
|
21
|
+
## Usage
|
54
22
|
|
55
|
-
|
56
|
-
|
57
|
-
|
23
|
+
```ruby
|
24
|
+
# Default values are provided
|
25
|
+
repetition = Repetition::Flashcard.new(easiness_factor: 2.5, interval: 0, repetitions: 0)
|
26
|
+
# Quality of recall: 0..5
|
27
|
+
# Returns: date of the next recall => <Date: 2018-08-09>
|
28
|
+
repetition.recall(4)
|
58
29
|
```
|
59
30
|
|
60
|
-
|
61
|
-
|
62
|
-
|
31
|
+
## Development
|
32
|
+
|
33
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
34
|
+
|
35
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
63
36
|
|
64
|
-
|
37
|
+
## Contributing
|
65
38
|
|
66
|
-
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dankimio/repetition.
|
67
40
|
|
68
|
-
|
69
|
-
Contributions are welcome! Feel free to post issues and create pull requests.
|
41
|
+
## License
|
70
42
|
|
43
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
3
|
|
4
|
-
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.libs << 'test'
|
6
|
+
t.libs << 'lib'
|
7
|
+
t.test_files = FileList['test/**/*_test.rb']
|
8
|
+
end
|
5
9
|
|
6
|
-
task :
|
10
|
+
task default: :test
|
data/bin/console
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'repetition'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
9
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require
|
10
|
+
# require 'pry'
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start
|
data/lib/repetition.rb
CHANGED
@@ -1,59 +1,70 @@
|
|
1
|
-
|
1
|
+
#
|
2
|
+
# The Repetition module uses the Super Memo method to determine when to next
|
3
|
+
# review an item. The quality values are as follows:
|
4
|
+
#
|
5
|
+
# 5 - perfect response
|
6
|
+
# 4 - correct response after a hesitation
|
7
|
+
# 3 - correct response recalled with serious difficulty
|
8
|
+
# 2 - incorrect response; where the correct one seemed easy to recall
|
9
|
+
# 1 - incorrect response; the correct one remembered
|
10
|
+
# 0 - complete blackout
|
11
|
+
#
|
12
|
+
# Find out more here: https://www.supermemo.com/english/ol/sm2.htm
|
13
|
+
#
|
2
14
|
|
3
15
|
require 'date'
|
4
16
|
|
5
17
|
module Repetition
|
6
|
-
|
7
|
-
|
8
|
-
self.number_repetitions = 0
|
9
|
-
self.quality_of_last_recall = nil
|
10
|
-
self.repetition_interval = nil
|
11
|
-
self.next_repetition = nil
|
12
|
-
self.last_studied = nil
|
13
|
-
end
|
18
|
+
class Flashcard
|
19
|
+
attr_reader :easiness_factor, :interval, :repetitions
|
14
20
|
|
15
|
-
|
16
|
-
|
17
|
-
|
21
|
+
def initialize(easiness_factor: 2.5, interval: 0, repetitions: 0)
|
22
|
+
@easiness_factor = easiness_factor
|
23
|
+
@interval = interval
|
24
|
+
@repetitions = repetitions
|
18
25
|
end
|
19
26
|
|
20
|
-
|
21
|
-
|
22
|
-
self.repetition_interval = 0
|
23
|
-
else
|
24
|
-
self.easiness_factor = calculate_easiness_factor(easiness_factor, quality_of_recall)
|
27
|
+
def recall(quality)
|
28
|
+
raise ArgumentError, 'Invalid quality of recall. Should be in range from 0 to 5.' unless (0..5).cover?(quality)
|
25
29
|
|
26
|
-
if
|
27
|
-
|
30
|
+
if quality < 3
|
31
|
+
# An incorrect recall is reset back to the beginning
|
32
|
+
@repetitions = 0
|
33
|
+
@interval = 0
|
34
|
+
elsif quality == 3
|
35
|
+
# The item was correctly recalled but should be tested again quickly
|
36
|
+
@interval = 0
|
28
37
|
else
|
29
|
-
|
38
|
+
# The item was correctly recalled and we can review later on
|
39
|
+
@repetitions += 1
|
30
40
|
|
31
|
-
case
|
41
|
+
case @repetitions
|
32
42
|
when 1
|
33
|
-
|
43
|
+
@interval = 1
|
34
44
|
when 2
|
35
|
-
|
45
|
+
@interval = 6
|
36
46
|
else
|
37
|
-
|
47
|
+
@easiness_factor = calculate_easiness_factor(@easiness_factor, quality)
|
48
|
+
@interval = interval * easiness_factor
|
38
49
|
end
|
39
50
|
end
|
40
|
-
end
|
41
51
|
|
42
|
-
|
43
|
-
|
44
|
-
end
|
52
|
+
due_on
|
53
|
+
end
|
45
54
|
|
46
|
-
|
47
|
-
|
48
|
-
|
55
|
+
def due_on
|
56
|
+
today + @interval
|
57
|
+
end
|
49
58
|
|
50
|
-
|
59
|
+
private
|
51
60
|
|
52
|
-
|
53
|
-
|
54
|
-
|
61
|
+
def today
|
62
|
+
@today ||= Date.today
|
63
|
+
end
|
55
64
|
|
56
|
-
|
57
|
-
|
65
|
+
def calculate_easiness_factor(easiness_factor, quality)
|
66
|
+
result = easiness_factor - 0.8 + (0.28 * quality) - (0.02 * quality * quality)
|
67
|
+
result < 1.3 ? 1.3 : result
|
68
|
+
end
|
58
69
|
end
|
59
70
|
end
|
data/lib/repetition/version.rb
CHANGED
data/repetition.gemspec
CHANGED
@@ -1,25 +1,24 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'repetition/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
6
|
+
spec.name = 'repetition'
|
8
7
|
spec.version = Repetition::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
8
|
+
spec.authors = ['Dan Kim']
|
9
|
+
spec.email = ['itsdanya@gmail.com']
|
11
10
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
11
|
+
spec.summary = 'Spaced repetition algorithm'
|
12
|
+
spec.description = 'Spaced repetition algorithm module that can be used as a mixin in Ruby apps'
|
13
|
+
spec.homepage = 'http://github.com/danyakim/repetition'
|
14
|
+
spec.license = 'MIT'
|
16
15
|
|
17
16
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir =
|
17
|
+
spec.bindir = 'exe'
|
19
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
21
20
|
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
22
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
23
|
+
spec.add_development_dependency 'rake', '~> 11.0'
|
25
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: repetition
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Kim
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,42 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.16'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.16'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '5.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '5.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '11.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '11.0'
|
55
55
|
description: Spaced repetition algorithm module that can be used as a mixin in Ruby
|
56
56
|
apps
|
57
57
|
email:
|
@@ -61,7 +61,10 @@ extensions: []
|
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
63
|
- ".gitignore"
|
64
|
+
- ".travis.yml"
|
65
|
+
- CHANGELOG.md
|
64
66
|
- Gemfile
|
67
|
+
- LICENSE.TXT
|
65
68
|
- README.md
|
66
69
|
- Rakefile
|
67
70
|
- bin/console
|
@@ -89,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
92
|
version: '0'
|
90
93
|
requirements: []
|
91
94
|
rubyforge_project:
|
92
|
-
rubygems_version: 2.6
|
95
|
+
rubygems_version: 2.7.6
|
93
96
|
signing_key:
|
94
97
|
specification_version: 4
|
95
98
|
summary: Spaced repetition algorithm
|