Module: Adept::DataFormats::DataFactories
- Included in:
- Bitstream
- Defined in:
- lib/adept/data_formats/data_factories.rb
Overview
Mixin which supports creating instances of data-storage containers from files. Classes which extend this mix-in should have a “from_string” class method.
Instance Method Summary collapse
-
#from_file(file) ⇒ Object
Creates a new instance of the target class from a file or filename.
Instance Method Details
#from_file(file) ⇒ Object
Creates a new instance of the target class from a file or filename.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/adept/data_formats/data_factories.rb', line 15 def from_file(file) #If we have a file object, read it into memory. if file.respond_to?(:read) file = file.read #Otherwise, assume we have a filename. else file = File::read(file) end #Create a new instance of the extending class from the given file. from_string(file) end |