thinking_lobster 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/thinking_lobster.rb +28 -26
  3. metadata +3 -59
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 218e6e4196ddcf31ccba598e4245801c6de55daa
4
- data.tar.gz: 20036c56a9646cee7d57263929cc5a9e2f0b0c03
3
+ metadata.gz: c3084e6508be42ea7843ff05e5cbe6c783f81838
4
+ data.tar.gz: 544d62472de65a0f8553e6be29ed64ad79a42a69
5
5
  SHA512:
6
- metadata.gz: def04bd5c774f5347cdd63e1c828959edfd62bdfd60e2c082ac68722c2e985638c482f08d1eb47caee437b49351e6627bd4f327d7f1413cf98e3fba364d3b7ba
7
- data.tar.gz: 3174c4d377ce067467366860c8c7c7fac47d849efbc374e1801a4464ec6f82686556fb23124401cd7eb5d50d2fc20d1653baa79b75e2aba3b3914ad731ab9af5
6
+ metadata.gz: 1fe663bedfbde5eb9498732a7993d608324d0b5da27e501ae6b8790ff54589386e427971cc44a849904a5313298fbfe327c2484621db3eb029c5433eea2f9f76
7
+ data.tar.gz: f48f6ae07847779b096c376220f7001b7d7e1dd196c5c513fdeb5723a778da4171abe23bb5562e9b2246dadccf5b7bf185d51bfaf7b2614d285c86882a0158db
@@ -1,20 +1,14 @@
1
1
  require 'mongoid'
2
2
  require 'active_support/time'
3
3
 
4
+ # Provides a way of intelligently scheduling review times for learning items stored in a MongoDB database.
4
5
  module ThinkingLobster
5
6
 
6
7
  #TODO:
7
- # [] Move all fixed numbers into user definable vars. eg. default review_due_at, intervals, etc
8
- # [x] Make protected members protected again
9
- # [x] Consider implementing a time_since_review method to replace time_since_due
10
- # [x] Write documentation
11
- # [x] Update the readme.md
12
- # [] Github pages for sdoc documentation
13
8
  # [] wiki pages for use cases, design philosophy.
14
- # [] Run a code coverage tool
9
+ # [] Run a test coverage tool
15
10
 
16
- # Includes a set of fields and support methods into the base class. Mongoid
17
- # must be included in the base class.
11
+ # Includes a set of fields and support methods into the base class. Mongoid must be included in the base class. Setup Mongoid before setting up this library.
18
12
  #
19
13
  # ==== Examples
20
14
  # class FlashCard
@@ -24,7 +18,6 @@ module ThinkingLobster
24
18
  # field :answer
25
19
  # end
26
20
  def self.included(collection)
27
- #Make all of the hardcoded 2's a user defined variable.
28
21
  collection.send :field, :times_reviewed, type: Integer, default: 0
29
22
  collection.send :field, :winning_streak, type: Integer, default: 0
30
23
  collection.send :field, :losing_streak, type: Integer, default: 0
@@ -40,12 +33,11 @@ module ThinkingLobster
40
33
  # * (Float) :new_positive_multiplier - The number by which a new item's interval is multiplied by when correctly reviewed. Default value is 2. Increasing this number will shorten the number of short term reviews. Must be greater than 1.0 . Be aware that there is no such thing as a new_negative_multiplier because incorrect new items get reset to the system default when incorrect.
41
34
  # * (Float) :old_positive_multiplier - The number by which an old item's interval is multiplied by when correctly reviewed. Default value is 1.25. Increasing this number will shorten the number of long term item reviews. Must be greater than 1.0 .
42
35
  # * (Float) :Penalty - The number by which an old item's interval is multiplied by when incorrectly answered. Can be any number equal to or greater than 0 or less than 1.0. Default value is 0.25 .
43
-
44
36
  mattr_accessor :config
45
37
 
46
38
  self.config = {
47
- cutoff: 36.hours,
48
- first_interval: 2.hours,
39
+ cutoff: 36*60*60, #36 hours
40
+ first_interval: 2*60*60, #2 hours
49
41
  new_positive_multiplier: 2.0,
50
42
  old_positive_multiplier: 1.25,
51
43
  penalty: 0.25
@@ -58,7 +50,7 @@ module ThinkingLobster
58
50
  # flash_card.mark_correct! # => #<SomeItem:0x123>
59
51
  #
60
52
  # Paramters:
61
- # * (Time) current_time - Time object by which review times are set. This parameter is almost always left to its default value (Time.now) but may be useful for testing or special use cases.
53
+ # * (Time) current_time - Time object by which review times are set. This parameter is almost always left to its default value (Time.now) but may be changed for testing or special use cases.
62
54
  #
63
55
  # Returns an instance of the base class
64
56
  def mark_correct!(current_time = Time.now)
@@ -80,7 +72,7 @@ module ThinkingLobster
80
72
  # flash_card.mark_incorrect! # => #<SomeItem:0x123>
81
73
  #
82
74
  # Parameters:
83
- # * (Time) current_time - Time object by which review times are set. Defaults to Time.now This parameter is typically left to its default value but may be useful for testing or special use cases.
75
+ # * (Time) current_time - Time object by which review times are set. Defaults to Time.now . This parameter is typically left to its default value but may be changed for testing or special use cases.
84
76
  #
85
77
  # Returns an instance of the base class.
86
78
  def mark_incorrect!(current_time = Time.now)
@@ -95,7 +87,7 @@ module ThinkingLobster
95
87
  self
96
88
  end
97
89
 
98
- # Indicates quantity of time since the item became ready for a review. This method is under consideration for deprecation in favor of a method which returns time since the last review.
90
+ # Indicates quantity of time since the item became ready for a review. This method is not used by ThinkingLobster at all, but may be useful as a helper method for application logic.
99
91
  #
100
92
  # Example:
101
93
  # flash_card = SomeDocument.new
@@ -135,7 +127,7 @@ module ThinkingLobster
135
127
  # flash_card = SomeDocument.new
136
128
  # flash_card.mark_correct!
137
129
  # flash_card.too_soon? # In this example, we just finished the review. So it won't be due for a few more hours.
138
- # # => false
130
+ # # => true
139
131
  #
140
132
  # * (Time) current_time - Time object which defaults to Time.now. This is the time by which the method compares.
141
133
  #
@@ -145,7 +137,7 @@ module ThinkingLobster
145
137
  if too_soon then true else false end
146
138
  end
147
139
 
148
- # Indicates if the item has a previous review set (which would indicate wether it is a newly added item).
140
+ # Indicates if the item has a previous review recorded (which would indicate wether it is a newly added item).
149
141
  #
150
142
  # Example:
151
143
  # flash_card = SomeDocument.new
@@ -158,7 +150,16 @@ module ThinkingLobster
158
150
  def previous_review?
159
151
  self.previous_review != nil
160
152
  end
153
+
161
154
  # Resets all attributes related to spaced repetition. You still need to call save on the item to persist.
155
+ #
156
+ # Example:
157
+ # really_bad_item.reset
158
+ # really_bad_item.save
159
+ # # => #<SomeItem:0x123> # This item is now a new item, for all practical purposes.
160
+ #
161
+ # Parameters:
162
+ # * (Time) current_time - The time that the items values will be reset to. Defaults to Time.now.
162
163
  def reset(current_time = Time.now)
163
164
  self.times_reviewed = 0
164
165
  self.winning_streak = 0
@@ -169,9 +170,14 @@ module ThinkingLobster
169
170
 
170
171
  protected
171
172
 
173
+ # Take a multiplier and a time, then returns a new interval.
174
+ def create_interval(multiplier, current_time = Time.now)
175
+ seconds_ago = time_since_review(current_time)
176
+ new_interval = seconds_ago * multiplier
177
+ self.review_due_at = current_time + new_interval
178
+ end
179
+
172
180
  def new_item_correct(current_time = Time.now)
173
- #Takes the interval between current_time and the time the item was due
174
- # And doubles that amount of time.
175
181
  if self.previous_review?
176
182
  self.set_previous_review!
177
183
  self.review_due_at += time_since_review(current_time) * @@config[:new_positive_multiplier]
@@ -191,15 +197,11 @@ module ThinkingLobster
191
197
  end
192
198
 
193
199
  def old_item_correct(current_time = Time.now)
194
- hours_ago = time_since_review(current_time)/60/60
195
- new_interval = (hours_ago * @@config[:old_positive_multiplier]).hours
196
- self.review_due_at = current_time + new_interval
200
+ self.create_interval(@@config[:old_positive_multiplier] , current_time)
197
201
  end
198
202
 
199
203
  def old_item_incorrect(current_time = Time.now)
200
- hours_ago = time_since_review(current_time)/60/60
201
- new_interval = (hours_ago * @@config[:penalty]).hours
202
- self.review_due_at = current_time + new_interval
204
+ self.create_interval(@@config[:penalty], current_time)
203
205
  end
204
206
 
205
207
  def increment_wins
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thinking_lobster
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rick Carlino
@@ -53,69 +53,13 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: bson_ext
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - '>='
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: mongo
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - '>='
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - '>='
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: pry
56
+ name: active_support
85
57
  requirement: !ruby/object:Gem::Requirement
86
58
  requirements:
87
59
  - - '>='
88
60
  - !ruby/object:Gem::Version
89
61
  version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - '>='
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: mongoid
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - '>='
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - '>='
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: sdoc
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - '>='
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
62
+ type: :runtime
119
63
  prerelease: false
120
64
  version_requirements: !ruby/object:Gem::Requirement
121
65
  requirements: