Class: TaliaCore::DataTypes::DataRecord
- Defined in:
- lib/talia_core/data_types/data_record.rb
Overview
Base class for all data records in Talia. This only contains a basic interface, without much functionality. All data-related methods will return a NotImplementedError
The DataRecord provides an interface to access a generic array/buffer of bytes, with the base class not making any assumptions on how these bytes are stored.
Subclasses should usually provide the inferface of this class, which is more or less like the standard file interface.
Each data record has a “location” field, which is roughly equivalent to the file name, and a MIME type. The default behaviour is that, if not set manually, the MIME type is automatically set before saving. It will be determined by the “file extension” of the location field.
Each data record must belong to an ActiveSource. For more information on how to handle records with files, see the FileRecord class
Direct Known Subclasses
Instance Attribute Summary collapse
-
#temp_path ⇒ Object
Returns the value of attribute temp_path.
Class Method Summary collapse
- .find_by_type_and_location!(source_data_type, location) ⇒ Object
-
.find_data_records(id) ⇒ Object
Find all data records about a specified source.
Instance Method Summary collapse
-
#all_bytes ⇒ Object
returns all bytes in the object as an array of unsigned integers.
-
#content_string ⇒ Object
Returns all_bytes as an binary string.
- #extract_mime_type(location) ⇒ Object
-
#get_byte(close_after_single_read = false) ⇒ Object
returns the next byte from the object, or nil at EOS.
- #mime_type ⇒ Object
-
#position ⇒ Object
returns the current position of the read cursor.
-
#reset ⇒ Object
reset the cursor to the initial state.
-
#seek(new_position) ⇒ Object
adjust the position of the read cursor.
-
#size ⇒ Object
returns the size of the object in bytes.
Instance Attribute Details
#temp_path ⇒ Object
Returns the value of attribute temp_path.
83 84 85 |
# File 'lib/talia_core/data_types/data_record.rb', line 83 def temp_path @temp_path end |
Class Method Details
.find_by_type_and_location!(source_data_type, location) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/talia_core/data_types/data_record.rb', line 93 def find_by_type_and_location!(source_data_type, location) # TODO: Should it directly instantiate the STI sub-class? # In this case we should use the following line instead. # # source_data = source_data_type.classify.constantize.find_by_location(location, :limit => 1) # data_type = "TaliaCore::DataTypes::#{source_data_type.camelize}" source_data = self.find(:first, :conditions => ["type = ? AND location = ?", data_type, location]) raise ActiveRecord::RecordNotFound if source_data.nil? source_data end |
.find_data_records(id) ⇒ Object
Find all data records about a specified source
89 90 91 |
# File 'lib/talia_core/data_types/data_record.rb', line 89 def find_data_records(id) find(:all, :conditions => { :source_id => id }) end |
Instance Method Details
#all_bytes ⇒ Object
returns all bytes in the object as an array of unsigned integers
39 40 41 |
# File 'lib/talia_core/data_types/data_record.rb', line 39 def all_bytes raise NotImplementedError end |
#content_string ⇒ Object
Returns all_bytes as an binary string
44 45 46 |
# File 'lib/talia_core/data_types/data_record.rb', line 44 def content_string all_bytes.pack('C*') if(all_bytes) end |
#extract_mime_type(location) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/talia_core/data_types/data_record.rb', line 72 def extract_mime_type(location) # Lookup the mime type for the extension (removing the dot # in front of the file extension) Works only for the file # types supported by Rails' Mime class. Mime::Type.lookup_by_extension((File.extname(location).downcase)[1..-1]).to_s end |
#get_byte(close_after_single_read = false) ⇒ Object
returns the next byte from the object, or nil at EOS
49 50 51 |
# File 'lib/talia_core/data_types/data_record.rb', line 49 def get_byte(close_after_single_read=false) raise NotImplementedError end |
#mime_type ⇒ Object
79 80 81 |
# File 'lib/talia_core/data_types/data_record.rb', line 79 def mime_type self.mime end |
#position ⇒ Object
returns the current position of the read cursor
54 55 56 |
# File 'lib/talia_core/data_types/data_record.rb', line 54 def position raise NotImplementedError end |
#reset ⇒ Object
reset the cursor to the initial state
69 70 |
# File 'lib/talia_core/data_types/data_record.rb', line 69 def reset end |
#seek(new_position) ⇒ Object
adjust the position of the read cursor
59 60 61 |
# File 'lib/talia_core/data_types/data_record.rb', line 59 def seek(new_position) raise NotImplementedError end |
#size ⇒ Object
returns the size of the object in bytes
64 65 66 |
# File 'lib/talia_core/data_types/data_record.rb', line 64 def size raise NotImplementedError end |