Class: StuffClassifier::InMemoryStorage
- Inherits:
-
Object
- Object
- StuffClassifier::InMemoryStorage
- Defined in:
- lib/stuff-classifier/storage.rb
Instance Method Summary collapse
-
#initialize ⇒ InMemoryStorage
constructor
A new instance of InMemoryStorage.
- #load_state(classifier) ⇒ Object
- #purge_state(classifier) ⇒ Object
- #save_state(classifier) ⇒ Object
Constructor Details
#initialize ⇒ InMemoryStorage
Returns a new instance of InMemoryStorage.
5 6 7 |
# File 'lib/stuff-classifier/storage.rb', line 5 def initialize @storage = {} end |
Instance Method Details
#load_state(classifier) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/stuff-classifier/storage.rb', line 9 def load_state(classifier) if @storage.key? classifier.name _wcount, _ccount = @storage[classifier.name] classifier.instance_eval do @wcount = _wcount @ccount = _ccount end end end |
#purge_state(classifier) ⇒ Object
26 27 28 |
# File 'lib/stuff-classifier/storage.rb', line 26 def purge_state(classifier) @storage.delete(classifier.name) end |
#save_state(classifier) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/stuff-classifier/storage.rb', line 19 def save_state(classifier) name = classifier.name wcount = classifier.instance_variable_get :@wcount ccount = classifier.instance_variable_get :@ccount @storage[name] = [wcount, ccount] end |