Class: Slick::Web::Node

Inherits:
Object show all
Defined in:
lib/slick/web/node.rb

Direct Known Subclasses

Dir, File

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil, name = nil) ⇒ Node

Returns a new instance of Node.



6
7
8
9
# File 'lib/slick/web/node.rb', line 6

def initialize(parent = nil, name = nil)
    @parent = parent
    @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/slick/web/node.rb', line 4

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



4
5
6
# File 'lib/slick/web/node.rb', line 4

def parent
  @parent
end

Instance Method Details

#dir?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/slick/web/node.rb', line 31

def dir?
    kind_of?(Slick::Web::Dir)
end

#file?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/slick/web/node.rb', line 27

def file?
    kind_of?(Slick::Web::File)
end

#relative_pathObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/slick/web/node.rb', line 11

def relative_path
    @relative_path ||= begin
        out = []
        current = self
        while current
            out.unshift(current.name)
            current = current.parent
        end
        out.join('/')
    end
end

#rootObject



23
24
25
# File 'lib/slick/web/node.rb', line 23

def root
    @root ||= parent ? parent.root : self
end