Class: Tendersync::Document::TOCEntry
- Inherits:
-
Object
- Object
- Tendersync::Document::TOCEntry
- Defined in:
- lib/tendersync/document.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#link ⇒ Object
readonly
Returns the value of attribute link.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #add(child) ⇒ Object
- #children ⇒ Object
-
#initialize(name, link = nil, level = nil) ⇒ TOCEntry
constructor
A new instance of TOCEntry.
-
#write_entries(io, depth = 1, indent = 0, doc_link = parent.link) ⇒ Object
Write this element and all children, recursively as bullet lists with links.
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
#level ⇒ Object (readonly)
Returns the value of attribute level.
12 13 14 |
# File 'lib/tendersync/document.rb', line 12 def level @level end |
#link ⇒ Object (readonly)
Returns the value of attribute link.
12 13 14 |
# File 'lib/tendersync/document.rb', line 12 def link @link end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/tendersync/document.rb', line 12 def name @name end |
#parent ⇒ Object
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 |
#children ⇒ Object
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 |