Class: StuffClassifier::Storage
- Inherits:
-
Object
- Object
- StuffClassifier::Storage
- Defined in:
- lib/stuff-classifier/storage.rb
Direct Known Subclasses
Defined Under Namespace
Modules: ActAsStorable
Instance Attribute Summary collapse
-
#storage ⇒ Object
Returns the value of attribute storage.
Instance Method Summary collapse
- #classifier_to_storage(classifier) ⇒ Object
- #clear_storage(classifier) ⇒ Object
-
#initialize(*opts) ⇒ Storage
constructor
A new instance of Storage.
- #storage_to_classifier(classifier) ⇒ Object
Constructor Details
#initialize(*opts) ⇒ Storage
Returns a new instance of Storage.
16 17 18 |
# File 'lib/stuff-classifier/storage.rb', line 16 def initialize(*opts) @storage = {} end |
Instance Attribute Details
#storage ⇒ Object
Returns the value of attribute storage.
14 15 16 |
# File 'lib/stuff-classifier/storage.rb', line 14 def storage @storage end |
Instance Method Details
#classifier_to_storage(classifier) ⇒ Object
28 29 30 31 |
# File 'lib/stuff-classifier/storage.rb', line 28 def classifier_to_storage(classifier) to_store = classifier.class.to_store + classifier.class.superclass.to_store @storage[classifier.name] = to_store.inject({}) {|h,var| h[var] = classifier.instance_variable_get("@#{var}");h} end |
#clear_storage(classifier) ⇒ Object
33 34 35 |
# File 'lib/stuff-classifier/storage.rb', line 33 def clear_storage(classifier) @storage.delete(classifier.name) end |
#storage_to_classifier(classifier) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/stuff-classifier/storage.rb', line 20 def storage_to_classifier(classifier) if @storage.key? classifier.name @storage[classifier.name].each do |var,value| classifier.instance_variable_set "@#{var}",value end end end |