Class: Classifier::Storage::File
- Defined in:
- lib/classifier/storage/file.rb
Overview
File-based storage backend.
Example:
bayes = Classifier::Bayes.new('Spam', 'Ham')
bayes.storage = Classifier::Storage::File.new(path: "/var/models/spam.json")
bayes.train_spam("Buy now!")
bayes.save
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #delete ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(path:) ⇒ File
constructor
A new instance of File.
- #read ⇒ Object
- #write(data) ⇒ Object
Constructor Details
#initialize(path:) ⇒ File
Returns a new instance of File.
25 26 27 28 |
# File 'lib/classifier/storage/file.rb', line 25 def initialize(path:) super() @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
22 23 24 |
# File 'lib/classifier/storage/file.rb', line 22 def path @path end |
Instance Method Details
#delete ⇒ Object
41 42 43 |
# File 'lib/classifier/storage/file.rb', line 41 def delete ::File.delete(@path) if exists? end |
#exists? ⇒ Boolean
46 47 48 |
# File 'lib/classifier/storage/file.rb', line 46 def exists? ::File.exist?(@path) end |
#read ⇒ Object
36 37 38 |
# File 'lib/classifier/storage/file.rb', line 36 def read exists? ? ::File.read(@path) : nil end |
#write(data) ⇒ Object
31 32 33 |
# File 'lib/classifier/storage/file.rb', line 31 def write(data) ::File.write(@path, data) end |