class Mexico::FileSystem::LocalFile
A LocalFile
object represents a file on a local file system, with additional information
Public Class Methods
Creates a new local file object. @option opts [String] :identifier The identifier of the new design (required). @option opts [String] :name The name of the new design. (required). @option opts [String] :description A description of the new design (optional).
# 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
Public Instance Methods
Resolves any relative path given in the path field, and returns an absolute path suited for the current operating system. @return (String) a string containing the absolute path to the file.
# File lib/mexico/file_system/local_file.rb, line 67 def absolute_path if path.starts_with? "." return File.expand_path(File.join(@corpus.base_path, path)) end return path end
This method performs additional linking and cleanup after parsing a XML representation.
# File lib/mexico/file_system/local_file.rb, line 97 def after_parse # puts "Parsed LocalFile" end
Indicates whether the file described at the path actually exists. @return (Boolean) true
if the described file exists, false
otherwise.
# File lib/mexico/file_system/local_file.rb, line 76 def file_exists? return false if path.blank? File.exists?(absolute_path) end
Returns a file object for this {LocalFile} object. @return (File) a file object for the described file, or nil
if there is no readable file at that location.
# File lib/mexico/file_system/local_file.rb, line 83 def file_handle return nil if path.blank? return File.open(absolute_path) end
Returns the size of the file (in bytes). @return (Integer) the size of the file in bytes, or nil
if no file can be found.
# File lib/mexico/file_system/local_file.rb, line 90 def file_size return nil if path.blank? return File.size(absolute_path) end