Class: Docco::Parser::Section
- Inherits:
-
Object
- Object
- Docco::Parser::Section
- Defined in:
- lib/docco/parser/section.rb
Constant Summary collapse
- HEADING_EXP =
/<\s*h([1-6])\b[^>]*>(.*?)<\/\s*h\1\s*>/im
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #<<(section) ⇒ Object
- #add_content(node, html) ⇒ Object
-
#initialize(node:, html:) ⇒ Section
constructor
A new instance of Section.
- #inspect ⇒ Object
- #level ⇒ Object
- #section? ⇒ Boolean
- #title ⇒ Object
- #title_html ⇒ Object
- #to_html ⇒ Object
Constructor Details
#initialize(node:, html:) ⇒ Section
Returns a new instance of Section.
10 11 12 13 14 15 16 |
# File 'lib/docco/parser/section.rb', line 10 def initialize(node:, html:) @node = node @title_html = html @id = node.attr['id'] @options = node. @nodes = [] end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/docco/parser/section.rb', line 8 def id @id end |
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
8 9 10 |
# File 'lib/docco/parser/section.rb', line 8 def nodes @nodes end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/docco/parser/section.rb', line 8 def @options end |
Instance Method Details
#<<(section) ⇒ Object
23 24 25 |
# File 'lib/docco/parser/section.rb', line 23 def <<(section) @nodes << section end |
#add_content(node, html) ⇒ Object
27 28 29 |
# File 'lib/docco/parser/section.rb', line 27 def add_content(node, html) @nodes << ContentNode.new(node, html) end |
#inspect ⇒ Object
18 |
# File 'lib/docco/parser/section.rb', line 18 def inspect = %(<#{self.class}:H#{level}##{id} [#{nodes.size} nodes]>) |
#level ⇒ Object
21 |
# File 'lib/docco/parser/section.rb', line 21 def level = @options[:level] |
#section? ⇒ Boolean
19 |
# File 'lib/docco/parser/section.rb', line 19 def section? = true |
#title ⇒ Object
33 34 35 |
# File 'lib/docco/parser/section.rb', line 33 def title @title ||= @title_html.match(HEADING_EXP)[2] end |
#title_html ⇒ Object
31 |
# File 'lib/docco/parser/section.rb', line 31 def title_html = @title_html |
#to_html ⇒ Object
37 38 39 40 41 |
# File 'lib/docco/parser/section.rb', line 37 def to_html @nodes.reduce(+title_html) do |str, node| str << "\n" << node.to_html end end |