Class: FFFS::FileSystem
Instance Attribute Summary
Attributes inherited from Directory
#filesystem, #name, #parent
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Directory
#[]=, #__path, #__set, #inspect, #load, #merge!, #method_missing, #push, #save, #to_a
Constructor Details
Returns a new instance of FileSystem.
43
44
45
46
47
48
|
# File 'lib/fffs/filesystem.rb', line 43
def initialize
@name = '/'
self.parent = self
self.filesystem = self
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class FFFS::Directory
Class Method Details
.load(path) ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/fffs/filesystem.rb', line 35
def self.load (path)
fs = self.new
fs.load(path)
return fs
end
|
.parse(text) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/fffs/filesystem.rb', line 27
def self.parse (text)
fs = self.new
fs.parse(text)
return fs
end
|
Instance Method Details
#parse(text) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/fffs/filesystem.rb', line 54
def parse (text)
separator = Regexp.escape(text.match(/^(.+)$/)[1])
text = text.sub(/^.*$/, '').gsub(/\r/, '')
data = text.split(/\n\n#{separator} (.+?) #{separator}\n\n/)
data.shift
data.each_slice(2) {|(name, content)|
if name.include?(' -> ')
t, name, link = name.match(/^(.*?) -> (.*?)$/)
end
path = ::File.dirname(name)
name = ::File.basename(name)
if path == '.'
parent = self
if link
self << Link.new(name, link)
else
self << File.new(name, content)
end
else
into = self
path.split('/').each {|dir|
into = into[dir] || (into << Directory.new(dir))
}
if link
into << Link.new(name, link)
else
into << File.new(name, content)
end
end
}
end
|
#path(path = nil) ⇒ Object
50
51
52
|
# File 'lib/fffs/filesystem.rb', line 50
def path (path=nil)
'/'
end
|