Class: DrawUml::Tree::Leaf

Inherits:
Object
  • Object
show all
Defined in:
lib/draw_uml/tree/leaf.rb

Direct Known Subclasses

Branch

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, level = 0, trunk = nil) ⇒ Leaf

Returns a new instance of Leaf.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/draw_uml/tree/leaf.rb', line 6

def initialize(path, level=0, trunk=nil)
  @name = File.basename(path, '.*')
  @path = File.expand_path(path)

  if trunk.nil?
    @level = level
    @trunk = path
    @id = :root
  else
    @level = level + 1
    @trunk = trunk
    @id = "#{File.dirname(@path)}/#{@name}".sub(trunk, '')
  end
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/draw_uml/tree/leaf.rb', line 4

def id
  @id
end

#levelObject (readonly)

Returns the value of attribute level.



4
5
6
# File 'lib/draw_uml/tree/leaf.rb', line 4

def level
  @level
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/draw_uml/tree/leaf.rb', line 4

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/draw_uml/tree/leaf.rb', line 4

def path
  @path
end

#trunkObject (readonly)

Returns the value of attribute trunk.



4
5
6
# File 'lib/draw_uml/tree/leaf.rb', line 4

def trunk
  @trunk
end

Instance Method Details

#leaf?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/draw_uml/tree/leaf.rb', line 21

def leaf?
  true
end