Class: Mexico::FileSystem::Resource

Inherits:
Object
  • Object
show all
Extended by:
IdRef, StaticCollectionRef
Includes:
BoundToCorpus, Poseidon, ROXML
Defined in:
lib/mexico/file_system/resource.rb

Overview

A template class doing nothing.

Instance Attribute Summary

Attributes included from BoundToCorpus

#corpus

Instance Method Summary collapse

Methods included from StaticCollectionRef

collection_ref

Methods included from IdRef

id_ref

Methods included from BoundToCorpus

#bind_to_corpus

Constructor Details

#initialize(opts = {}) ⇒ Resource

creates a new Trial object.

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :identifier (String)

    The identifier of the new trial object.

  • :name (String)

    The name of the new trial object.

  • :description (String)

    The identifier of the new trial object.


84
85
86
87
88
89
# 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

Instance Method Details

#after_parseObject

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


168
169
170
# File 'lib/mexico/file_system/resource.rb', line 168

def after_parse
  # puts "Parsed Resource #{self.identifier}"
end

#complete_file_sizeInteger

Returns the disk space in bytes used by all local files of this resource.

Returns:

  • (Integer)

    disk space in bytes used by all local files of this resource.


106
107
108
# File 'lib/mexico/file_system/resource.rb', line 106

def complete_file_size
  local_files.collect{ |f| f.file_size }.inject(:+)
end

#documentMexico::FileSystem::FiestaDocument

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).

Returns:


163
164
165
# File 'lib/mexico/file_system/resource.rb', line 163

def document
 defined?(@document) ? @document : nil
end

#is_annotation?Boolean

Indicates whether this resource is of the annotation media type.

Returns:

  • (Boolean)

    true if this resource has media type annotation, false otherwise.


124
125
126
# File 'lib/mexico/file_system/resource.rb', line 124

def is_annotation?
  return media_type==::Mexico::Constants::MediaTypes::ANNOTATION
end

#is_audio?Boolean

Indicates whether this resource is of the audio media type.

Returns:

  • (Boolean)

    true if this resource has media type audio, false otherwise.


118
119
120
# File 'lib/mexico/file_system/resource.rb', line 118

def is_audio?
  return media_type==::Mexico::Constants::MediaTypes::AUDIO
end

#is_video?Boolean

Indicates whether this resource is of the video media type.

Returns:

  • (Boolean)

    true if this resource has media type video, false otherwise.


112
113
114
# File 'lib/mexico/file_system/resource.rb', line 112

def is_video?
  return media_type==::Mexico::Constants::MediaTypes::VIDEO
end

#linked_to_design_component?true, false

Indicates whether this resource is associated with a design component.

Returns:

  • (true, false)

    true if this resource belongs to a design component, false otherwise.


100
101
102
# File 'lib/mexico/file_system/resource.rb', line 100

def linked_to_design_component?
  return design_component!=nil
end

#linked_to_trial?true, false

Indicates whether this resource is associated with a trial.

Returns:

  • (true, false)

    true if this resource belongs to a trial, false otherwise.


94
95
96
# File 'lib/mexico/file_system/resource.rb', line 94

def linked_to_trial?
  return trial!=nil
end

#loadMexico::FileSystem::FiestaDocument

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.)

Returns:


131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# 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