Class: TaliaCore::DataTypes::DataRecord

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/talia_core/data_types/data_record.rb

Overview

ActiveRecord interface to the data record in the database

Direct Known Subclasses

FileRecord, MediaLink

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#temp_pathObject

Returns the value of attribute temp_path.



61
62
63
# File 'lib/talia_core/data_types/data_record.rb', line 61

def temp_path
  @temp_path
end

Class Method Details

.find_by_type_and_location!(source_data_type, location) ⇒ Object

Raises:

  • (ActiveRecord::RecordNotFound)


71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/talia_core/data_types/data_record.rb', line 71

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



67
68
69
# File 'lib/talia_core/data_types/data_record.rb', line 67

def find_data_records(id)
  find(:all, :conditions => { :source_id => id })
end

Instance Method Details

#all_bytesObject

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



22
23
# File 'lib/talia_core/data_types/data_record.rb', line 22

def all_bytes
end

#content_stringObject

Returns all_bytes as an binary string



26
27
28
# File 'lib/talia_core/data_types/data_record.rb', line 26

def content_string
  all_bytes.pack('C*') if(all_bytes)
end

#extract_mime_type(location) ⇒ Object



50
51
52
53
54
55
# File 'lib/talia_core/data_types/data_record.rb', line 50

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



31
32
# File 'lib/talia_core/data_types/data_record.rb', line 31

def get_byte(close_after_single_read=false)
end

#mime_typeObject



57
58
59
# File 'lib/talia_core/data_types/data_record.rb', line 57

def mime_type
  self.mime
end

#positionObject

returns the current position of the read cursor



35
36
# File 'lib/talia_core/data_types/data_record.rb', line 35

def position
end

#resetObject

reset the cursor to the initial state



47
48
# File 'lib/talia_core/data_types/data_record.rb', line 47

def reset
end

#seek(new_position) ⇒ Object

adjust the position of the read cursor



39
40
# File 'lib/talia_core/data_types/data_record.rb', line 39

def seek(new_position)
end

#sizeObject

returns the size of the object in bytes



43
44
# File 'lib/talia_core/data_types/data_record.rb', line 43

def size
end