Class: Algerb::Files

Inherits:
Object
  • Object
show all
Includes:
Util, Enumerable
Defined in:
lib/algerb/files.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#file_to_class, #indentation, #remove_dir, #remove_ext, #split_dir_and_file, #split_path_as_head_and_tail

Constructor Details

#initialize(name = nil, files = {}) ⇒ Files

Returns a new instance of Files.



7
8
9
10
# File 'lib/algerb/files.rb', line 7

def initialize(name = nil, files = {})
  @name = name
  @files = files
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



5
6
7
# File 'lib/algerb/files.rb', line 5

def files
  @files
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/algerb/files.rb', line 5

def name
  @name
end

Class Method Details

.root(files = {}) ⇒ Object



12
13
14
# File 'lib/algerb/files.rb', line 12

def self.root(files = {})
  new(nil, files)
end

Instance Method Details

#==(another) ⇒ Object



35
36
37
# File 'lib/algerb/files.rb', line 35

def ==(another)
  self.name == another.name and self.files == another.files
end

#add(file) ⇒ Object



16
17
18
19
# File 'lib/algerb/files.rb', line 16

def add(file)
  @files[file.name] = file unless @files.has_key?(file.name)
  self
end

#find_by_path(path) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/algerb/files.rb', line 21

def find_by_path(path)
  next_path, rest = split_path_as_head_and_tail(path)
  if files.has_key?(next_path)
    found = files[next_path]
    if rest.nil?
      found
    elsif found.is_a?(Algerb::Files)
      found.find_by_path(rest)
    else
      found
    end
  end
end