Class: Tendersync::Document::TOCEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/tendersync/document.rb

Direct Known Subclasses

Group

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, link = nil, level = nil) ⇒ TOCEntry

Returns a new instance of TOCEntry.



14
15
16
17
18
# File 'lib/tendersync/document.rb', line 14

def initialize name, link=nil, level=nil
  @name = name
  @link = link if link
  @level = level if level
end

Instance Attribute Details

#levelObject (readonly)

Returns the value of attribute level.



12
13
14
# File 'lib/tendersync/document.rb', line 12

def level
  @level
end

Returns the value of attribute link.



12
13
14
# File 'lib/tendersync/document.rb', line 12

def link
  @link
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/tendersync/document.rb', line 12

def name
  @name
end

#parentObject

Returns the value of attribute parent.



13
14
15
# File 'lib/tendersync/document.rb', line 13

def parent
  @parent
end

Instance Method Details

#add(child) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/tendersync/document.rb', line 33

def add child
  if !parent || child.level > self.level
    children << child
    child.parent = self
  else
    parent.add(child)
  end
  child
end

#childrenObject



19
20
21
# File 'lib/tendersync/document.rb', line 19

def children
  @children ||= []
end

#write_entries(io, depth = 1, indent = 0, doc_link = parent.link) ⇒ Object

Write this element and all children, recursively as bullet lists with links



23
24
25
26
27
28
29
30
31
32
# File 'lib/tendersync/document.rb', line 23

def write_entries(io, depth=1, indent = 0, doc_link = parent.link)
  io.write " " * 4 * indent # indentation
  io.write "* " # bullet
  if link
    io.puts "[#{name}](#{doc_link}##{self.link})"
  else
    io.puts name
  end
  children.each { | child | child.write_entries(io, depth-1, indent+1, doc_link)} unless depth == 1
end