Module: PathMapper::BaseNode

Included in:
DirNode, FileNode, NullNode
Defined in:
lib/path_mapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_nameObject (readonly)

Returns the value of attribute _name.



17
18
19
# File 'lib/path_mapper.rb', line 17

def _name
  @_name
end

#_pathObject (readonly)

Returns the value of attribute _path.



16
17
18
# File 'lib/path_mapper.rb', line 16

def _path
  @_path
end

Instance Method Details

#_grep(reg, recursive = false) ⇒ Object



24
25
26
27
28
# File 'lib/path_mapper.rb', line 24

def _grep(reg, recursive=false)
  path = "#{@_path}#{'/**' if recursive}/*"
  files = Dir[path].select {|f| f =~ reg }
  FilesIterator.new(files)
end

#_grep_dirs(recursive = false) ⇒ Object



30
31
32
# File 'lib/path_mapper.rb', line 30

def _grep_dirs(recursive=false)
  self._grep(/.*/).select {|n| n.is_a? DirNode }
end

#_grep_files(recursive = false) ⇒ Object



34
35
36
# File 'lib/path_mapper.rb', line 34

def _grep_files(recursive=false)
  self._grep(/.*/).select {|n| n.is_a? FileNode }
end

#get_file_name(name) ⇒ Object



38
39
40
# File 'lib/path_mapper.rb', line 38

def get_file_name(name)
  name.scan(/[^\/]+/).last
end

#initialize(path) ⇒ Object



19
20
21
22
# File 'lib/path_mapper.rb', line 19

def initialize(path)
  @_path = path
  @_name = get_file_name(path)
end

#inspectObject



46
47
48
# File 'lib/path_mapper.rb', line 46

def inspect
  self.to_s
end

#to_sObject Also known as: to_str



42
43
44
# File 'lib/path_mapper.rb', line 42

def to_s
  @_path
end