Class: Mizuho::Heading
- Inherits:
-
Object
- Object
- Mizuho::Heading
- Defined in:
- lib/mizuho/heading.rb
Instance Attribute Summary collapse
-
#anchor ⇒ Object
Returns the value of attribute anchor.
-
#basename ⇒ Object
Returns the value of attribute basename.
-
#children ⇒ Object
Returns the value of attribute children.
-
#level ⇒ Object
Returns the value of attribute level.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#title ⇒ Object
The heading title, as HTML.
Instance Method Summary collapse
- #each_descendant(&block) ⇒ Object
- #find_parent_with_level(level) ⇒ Object
-
#initialize ⇒ Heading
constructor
A new instance of Heading.
-
#plain_title ⇒ Object
The heading title without section number, as plain text.
-
#title_without_numbers ⇒ Object
The heading title without section number, as HTML.
Constructor Details
#initialize ⇒ Heading
Returns a new instance of Heading.
14 15 16 |
# File 'lib/mizuho/heading.rb', line 14 def initialize @children = [] end |
Instance Attribute Details
#anchor ⇒ Object
Returns the value of attribute anchor.
10 11 12 |
# File 'lib/mizuho/heading.rb', line 10 def anchor @anchor end |
#basename ⇒ Object
Returns the value of attribute basename.
9 10 11 |
# File 'lib/mizuho/heading.rb', line 9 def basename @basename end |
#children ⇒ Object
Returns the value of attribute children.
12 13 14 |
# File 'lib/mizuho/heading.rb', line 12 def children @children end |
#level ⇒ Object
Returns the value of attribute level.
8 9 10 |
# File 'lib/mizuho/heading.rb', line 8 def level @level end |
#parent ⇒ Object
Returns the value of attribute parent.
11 12 13 |
# File 'lib/mizuho/heading.rb', line 11 def parent @parent end |
#title ⇒ Object
The heading title, as HTML. Non-HTML special characters are already escaped.
7 8 9 |
# File 'lib/mizuho/heading.rb', line 7 def title @title end |
Instance Method Details
#each_descendant(&block) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/mizuho/heading.rb', line 38 def each_descendant(&block) children.each do |h| block.call(h) h.each_descendant(&block) end end |
#find_parent_with_level(level) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/mizuho/heading.rb', line 18 def find_parent_with_level(level) h = self while h && h.level != level h = h.parent end return h end |
#plain_title ⇒ Object
The heading title without section number, as plain text. Contains no HTML elements. Non-HTML special characters are NOT escaped.
34 35 36 |
# File 'lib/mizuho/heading.rb', line 34 def plain_title return CGI::unescapeHTML(title_without_numbers.gsub(%r{</?[a-z]+>}i, '')) end |
#title_without_numbers ⇒ Object
The heading title without section number, as HTML. Non-HTML special characters are already escaped.
28 29 30 |
# File 'lib/mizuho/heading.rb', line 28 def title_without_numbers return title.sub(/^(\d+\.)+ /, '') end |