Class: Mizuho::Heading

Inherits:
Object
  • Object
show all
Defined in:
lib/mizuho/heading.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHeading

Returns a new instance of Heading.



14
15
16
# File 'lib/mizuho/heading.rb', line 14

def initialize
	@children = []
end

Instance Attribute Details

#anchorObject

Returns the value of attribute anchor.



10
11
12
# File 'lib/mizuho/heading.rb', line 10

def anchor
  @anchor
end

#basenameObject

Returns the value of attribute basename.



9
10
11
# File 'lib/mizuho/heading.rb', line 9

def basename
  @basename
end

#childrenObject

Returns the value of attribute children.



12
13
14
# File 'lib/mizuho/heading.rb', line 12

def children
  @children
end

#levelObject

Returns the value of attribute level.



8
9
10
# File 'lib/mizuho/heading.rb', line 8

def level
  @level
end

#parentObject

Returns the value of attribute parent.



11
12
13
# File 'lib/mizuho/heading.rb', line 11

def parent
  @parent
end

#titleObject

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_titleObject

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_numbersObject

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