Class: Mexico::FileSystem::LocalFile
- Inherits:
-
Object
- Object
- Mexico::FileSystem::LocalFile
- Extended by:
- IdRef, StaticCollectionRef
- Includes:
- BoundToCorpus, Poseidon, ROXML
- Defined in:
- lib/mexico/file_system/local_file.rb
Overview
A LocalFile object represents a file on a local file system, with additional information
Instance Attribute Summary
Attributes included from BoundToCorpus
Instance Method Summary collapse
-
#absolute_path ⇒ String
Resolves any relative path given in the path field, and returns an absolute path suited for the current operating system.
-
#after_parse ⇒ Object
This method performs additional linking and cleanup after parsing a XML representation.
-
#file_exists? ⇒ Boolean
Indicates whether the file described at the path actually exists.
-
#file_handle ⇒ File
Returns a file object for this LocalFile object.
-
#file_size ⇒ Integer
Returns the size of the file (in bytes).
-
#initialize(opts = {}) ⇒ LocalFile
constructor
Creates a new local file object.
Methods included from IdRef
Methods included from StaticCollectionRef
Methods included from BoundToCorpus
Constructor Details
#initialize(opts = {}) ⇒ LocalFile
Creates a new local file object.
58 59 60 61 62 |
# File 'lib/mexico/file_system/local_file.rb', line 58 def initialize(opts={}) [:identifier,:name,:description].each do |att| send("#{att}=", opts[att]) if opts.has_key?(att) end end |
Instance Method Details
#absolute_path ⇒ String
Resolves any relative path given in the path field, and returns an absolute path suited for the current operating system.
67 68 69 70 71 72 |
# File 'lib/mexico/file_system/local_file.rb', line 67 def absolute_path if path.starts_with? "." return File.(File.join(@corpus.base_path, path)) end return path end |
#after_parse ⇒ Object
This method performs additional linking and cleanup after parsing a XML representation.
97 98 99 |
# File 'lib/mexico/file_system/local_file.rb', line 97 def after_parse # puts "Parsed LocalFile" end |
#file_exists? ⇒ Boolean
Indicates whether the file described at the path actually exists.
76 77 78 79 |
# File 'lib/mexico/file_system/local_file.rb', line 76 def file_exists? return false if path.blank? File.exists?(absolute_path) end |
#file_handle ⇒ File
Returns a file object for this Mexico::FileSystem::LocalFile object.
83 84 85 86 |
# File 'lib/mexico/file_system/local_file.rb', line 83 def file_handle return nil if path.blank? return File.open(absolute_path) end |
#file_size ⇒ Integer
Returns the size of the file (in bytes).
90 91 92 93 |
# File 'lib/mexico/file_system/local_file.rb', line 90 def file_size return nil if path.blank? return File.size(absolute_path) end |