repetition 1.0.2 → 2.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: bab3c51f0e4592dd7fc82d9731b58a0fd323ca80
4
- data.tar.gz: 524371c1e719cf976ca4986fb3aefed473565725
2
+ SHA256:
3
+ metadata.gz: 395411bf8918658d462f941a292cf0ed689987505f30c13e31843fad1e45e38a
4
+ data.tar.gz: bc4232618f5ebde02ee0b6c63daf4b21217a43bb9aa29a8230279f374bd9d67c
5
5
  SHA512:
6
- metadata.gz: 0a3cbbabf457be18665be1c8f52f1867d109711f8c740e5ada8df8339dd74eca10c5189346cae00241793611d26582201c8f6f4da31c5d6c48f2947f33cbbe88
7
- data.tar.gz: 813ad91b742549a0c9c9478cfaf7b0f9082032440919c1b3c7745040bd89f2bc62e1dc70619c44103cfa2293a64f4b11a97a121aa69565e3c2a83472f11e610e
6
+ metadata.gz: b0b276d0d13d1515c656b967a397ad89bcf50925c66920a7f1daf65eda1ef8136b021e44ed6751b748dc2da4b9db7a9fa8d0a2037cc3f578a431729448ab8276
7
+ data.tar.gz: e1bb3c765debf1b8b1acafdb75e9477581d36d9ba4d062c408d1e31d63a164088798cf9a9c76a740fb89fab9fb7382bc75198c12c8219b9331cc560962d4f7a7
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.1
@@ -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
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
3
5
  # Specify your gem's dependencies in repetition.gemspec
4
6
  gemspec
@@ -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 gem
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
- or install from RubyGems
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
- ### Rails
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
- change_table :cards do |t|
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
- ### Usage
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
- This will add a bunch of properties to your model:
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
- Make sure that appropriate fields are created in your database using migrations
17
+ Or install it yourself as:
46
18
 
47
- You can now use all methods that are provided by gem, use `process_recall_result(quality)` method to update next repetition date. Method takes one argument which should be integer in range from 0 to 5 (0 - again, 5 - perfect).
48
- ```ruby
49
- card = Card.first
50
- card.reset_spaced_repetition_data # Reset data for first use
19
+ $ gem install repetition
51
20
 
52
- card.next_repetition # => nil
53
- card.process_recall_result(4)
21
+ ## Usage
54
22
 
55
- card.repetition_interval # => 1
56
- card.next_repetition # Tomorrow
57
- card.save # Don't forget to save your card!
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
- ### Changelog
61
- #### 1.0
62
- * Initial version
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
- ### Running Specs
37
+ ## Contributing
65
38
 
66
- `bundle exec rake`
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dankimio/repetition.
67
40
 
68
- ### Contributing
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 "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
3
 
4
- RSpec::Core::RakeTask.new(:spec)
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 :default => :spec
10
+ task default: :test
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "repetition"
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 "pry"
10
+ # require 'pry'
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
@@ -1,59 +1,70 @@
1
- require 'repetition/version'
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
- def reset_spaced_repetition_data
7
- self.easiness_factor = 2.5
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
- def process_recall_result(quality_of_recall)
16
- unless (1..5).include?(quality_of_recall)
17
- raise 'Invalid quality of recall. Should be in range from 1 to 5.'
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
- if quality_of_recall < 3
21
- self.number_repetitions = 0
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 quality_of_recall == 3
27
- self.repetition_interval = 0
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
- self.number_repetitions += 1
38
+ # The item was correctly recalled and we can review later on
39
+ @repetitions += 1
30
40
 
31
- case number_repetitions
41
+ case @repetitions
32
42
  when 1
33
- self.repetition_interval = 1
43
+ @interval = 1
34
44
  when 2
35
- self.repetition_interval = 6
45
+ @interval = 6
36
46
  else
37
- self.repetition_interval = repetition_interval * easiness_factor
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
- self.next_repetition = Date.today + repetition_interval
43
- self.last_studied = Date.today
44
- end
52
+ due_on
53
+ end
45
54
 
46
- def scheduled_to_recall?
47
- !next_repetition.nil? && next_repetition <= Date.today
48
- end
55
+ def due_on
56
+ today + @interval
57
+ end
49
58
 
50
- private
59
+ private
51
60
 
52
- def calculate_easiness_factor(easiness_factor, quality_of_recall)
53
- q = quality_of_recall
54
- ef_old = easiness_factor
61
+ def today
62
+ @today ||= Date.today
63
+ end
55
64
 
56
- result = ef_old - 0.8 + (0.28 * q) - (0.02 * q * q)
57
- result < 1.3 ? 1.3 : result
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
@@ -1,3 +1,3 @@
1
1
  module Repetition
2
- VERSION = '1.0.2'
2
+ VERSION = '2.0.0'
3
3
  end
@@ -1,25 +1,24 @@
1
- # coding: utf-8
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 = "repetition"
6
+ spec.name = 'repetition'
8
7
  spec.version = Repetition::VERSION
9
- spec.authors = ["Dan Kim"]
10
- spec.email = ["itsdanya@gmail.com"]
8
+ spec.authors = ['Dan Kim']
9
+ spec.email = ['itsdanya@gmail.com']
11
10
 
12
- spec.summary = %q{Spaced repetition algorithm}
13
- spec.description = %q{Spaced repetition algorithm module that can be used as a mixin in Ruby apps}
14
- spec.homepage = "http://github.com/danyakim/repetition"
15
- spec.license = "MIT"
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 = "exe"
17
+ spec.bindir = 'exe'
19
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
21
20
 
22
- spec.add_development_dependency "bundler", "~> 1.13"
23
- spec.add_development_dependency "rake", "~> 11.0"
24
- spec.add_development_dependency "rspec", "~> 3.0"
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: 1.0.2
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: 2017-04-10 00:00:00.000000000 Z
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.13'
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.13'
26
+ version: '1.16'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '11.0'
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: '11.0'
40
+ version: '5.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
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: '3.0'
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.11
95
+ rubygems_version: 2.7.6
93
96
  signing_key:
94
97
  specification_version: 4
95
98
  summary: Spaced repetition algorithm