class Mexico::FileSystem::Resource

A template class doing nothing.

Public Class Methods

new(opts={}) click to toggle source

creates a new Trial object. @option opts [String] :identifier The identifier of the new trial object. @option opts [String] :name The name of the new trial object. @option opts [String] :description The identifier of the new trial object.

# File lib/mexico/file_system/resource.rb, line 84
def initialize(opts={})
  # @corpus = corpus
  [:identifier,:name,:description].each do |att|
    send("#{att}=", opts[att]) if opts.has_key?(att)
  end
end

Public Instance Methods

after_parse() click to toggle source

This method performs additional linking and cleanup after parsing a XML representation.

# File lib/mexico/file_system/resource.rb, line 168
def after_parse
  # puts "Parsed Resource #{self.identifier}"
end
complete_file_size() click to toggle source

Returns the disk space in bytes used by all local files of this resource. @return (Integer) disk space in bytes used by all local files of this resource.

# File lib/mexico/file_system/resource.rb, line 106
def complete_file_size
  local_files.collect{ |f| f.file_size }.inject(:+)
end
document() click to toggle source

Returns the annotation document previously loaded in {#load} (this is only the case if resource has media type video, and if an appropriate local file is present). @return (Mexico::FileSystem::FiestaDocument) the document, or nil if no document has been loaded.

# File lib/mexico/file_system/resource.rb, line 163
def document
 defined?(@document) ? @document : nil
end
is_annotation?() click to toggle source

Indicates whether this resource is of the annotation media type. @return (Boolean) true if this resource has media type annotation, false otherwise.

# File lib/mexico/file_system/resource.rb, line 124
def is_annotation?
  return media_type==::Mexico::Constants::MediaTypes::ANNOTATION
end
is_audio?() click to toggle source

Indicates whether this resource is of the audio media type. @return (Boolean) true if this resource has media type audio, false otherwise.

# File lib/mexico/file_system/resource.rb, line 118
def is_audio?
  return media_type==::Mexico::Constants::MediaTypes::AUDIO
end
is_video?() click to toggle source

Indicates whether this resource is of the video media type. @return (Boolean) true if this resource has media type video, false otherwise.

# File lib/mexico/file_system/resource.rb, line 112
def is_video?
  return media_type==::Mexico::Constants::MediaTypes::VIDEO
end
linked_to_design_component?() click to toggle source

Indicates whether this resource is associated with a design component. @return [true,false] true if this resource belongs to a design component, false otherwise.

# File lib/mexico/file_system/resource.rb, line 100
def linked_to_design_component?
  return design_component!=nil
end
linked_to_trial?() click to toggle source

Indicates whether this resource is associated with a trial. @return [true,false] true if this resource belongs to a trial, false otherwise.

# File lib/mexico/file_system/resource.rb, line 94
def linked_to_trial?
  return trial!=nil
end
load() click to toggle source

Attempts to load the contents of the resource from an appropriate source into an appropriate data structure (for annotation files, into the ToE format, etc.) @return (Mexico::FileSystem::FiestaDocument) the document, or nil if no document could be loaded.

# File lib/mexico/file_system/resource.rb, line 131
def load

  # @todo create a loader interface in a separate package
  #       load() then takes a file or url, gets the contents as a stream,
  #              and puts it into appropriate data structures.
  #       choice depends on: MediaType. Whether LocalFile or URL are available.
  #       What kinds of LF / URL are available, and which one is the newest.
  # first goal: When document is of mediatype ANNOTATION, and there is one
  # LocalFile, and it is of a matching type (now: ToE import), then import that
  # one and make the resulting objects available below the resource.

  # first version:
  # if resource is annotation, and there is a toe file, then: load that toe file
  # as a document, and define the appropriate member variable.

  # puts "Is anno? %s" % is_annotation?
  if is_annotation?

    # puts "Toe File? %s" % local_files.find{ |f| f.path=~/toe$/ }
    toe_file = local_files.find{ |f| f.path=~/toe$/ || f.path=~/fiesta$/ }

    unless toe_file.nil?
      @document = ::Mexico::FileSystem::FiestaDocument.open(toe_file.absolute_path)
      @document.resource = self
      return @document
    end
  end
end