Class: Mexico::FileSystem::Resource
- Inherits:
-
Object
- Object
- Mexico::FileSystem::Resource
- 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
Instance Method Summary collapse
-
#after_parse ⇒ Object
This method performs additional linking and cleanup after parsing a XML representation.
-
#complete_file_size ⇒ Integer
Returns the disk space in bytes used by all local files of this resource.
-
#document ⇒ Mexico::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).
-
#initialize(opts = {}) ⇒ Resource
constructor
creates a new Trial object.
-
#is_annotation? ⇒ Boolean
Indicates whether this resource is of the annotation media type.
-
#is_audio? ⇒ Boolean
Indicates whether this resource is of the audio media type.
-
#is_video? ⇒ Boolean
Indicates whether this resource is of the video media type.
-
#linked_to_design_component? ⇒ true, false
Indicates whether this resource is associated with a design component.
-
#linked_to_trial? ⇒ true, false
Indicates whether this resource is associated with a trial.
-
#load ⇒ Mexico::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.).
Methods included from IdRef
Methods included from StaticCollectionRef
Methods included from BoundToCorpus
Constructor Details
#initialize(opts = {}) ⇒ Resource
creates a 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_parse ⇒ Object
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_size ⇒ Integer
Returns the 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 |
#document ⇒ Mexico::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).
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.
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.
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.
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.
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.
94 95 96 |
# File 'lib/mexico/file_system/resource.rb', line 94 def linked_to_trial? return trial!=nil end |
#load ⇒ Mexico::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.)
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 |