Class TaliaCore::DataTypes::DataRecord
In: lib/talia_core/data_types/data_record.rb
Parent: ActiveRecord::Base

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

Methods

Attributes

temp_path  [RW] 

Public Class methods

[Source]

     # File lib/talia_core/data_types/data_record.rb, line 93
 93:         def find_by_type_and_location!(source_data_type, location)
 94:           # TODO: Should it directly instantiate the STI sub-class?
 95:           # In this case we should use the following line instead.
 96:           #
 97:           # source_data = source_data_type.classify.constantize.find_by_location(location, :limit => 1)
 98:           #
 99:           data_type = "TaliaCore::DataTypes::#{source_data_type.camelize}"
100:           source_data = self.find(:first, :conditions => ["type = ? AND location = ?", data_type, location])
101:           
102:           raise ActiveRecord::RecordNotFound if source_data.nil?
103:           source_data
104:         end

Find all data records about a specified source

[Source]

    # File lib/talia_core/data_types/data_record.rb, line 89
89:         def find_data_records(id)
90:           find(:all, :conditions => { :source_id => id })
91:         end

Public Instance methods

returns all bytes in the object as an array of unsigned integers

[Source]

    # File lib/talia_core/data_types/data_record.rb, line 39
39:       def all_bytes
40:         raise NotImplementedError
41:       end

Returns all_bytes as an binary string

[Source]

    # File lib/talia_core/data_types/data_record.rb, line 44
44:       def content_string
45:         all_bytes.pack('C*') if(all_bytes)
46:       end

[Source]

    # File lib/talia_core/data_types/data_record.rb, line 72
72:       def extract_mime_type(location)
73:         # Lookup the mime type for the extension (removing the dot
74:         # in front of the file extension) Works only for the file
75:         # types supported by Rails' Mime class.
76:         Mime::Type.lookup_by_extension((File.extname(location).downcase)[1..-1]).to_s
77:       end

returns the next byte from the object, or nil at EOS

[Source]

    # File lib/talia_core/data_types/data_record.rb, line 49
49:       def get_byte(close_after_single_read=false)
50:         raise NotImplementedError
51:       end

[Source]

    # File lib/talia_core/data_types/data_record.rb, line 79
79:       def mime_type
80:         self.mime
81:       end

returns the current position of the read cursor

[Source]

    # File lib/talia_core/data_types/data_record.rb, line 54
54:       def position
55:         raise NotImplementedError
56:       end

reset the cursor to the initial state

[Source]

    # File lib/talia_core/data_types/data_record.rb, line 69
69:       def reset
70:       end

adjust the position of the read cursor

[Source]

    # File lib/talia_core/data_types/data_record.rb, line 59
59:       def seek(new_position)
60:         raise NotImplementedError
61:       end

returns the size of the object in bytes

[Source]

    # File lib/talia_core/data_types/data_record.rb, line 64
64:       def size
65:         raise NotImplementedError
66:       end

[Validate]