Class: PPZ::LeafSectionModel
- Inherits:
-
AbstractSectionModel
- Object
- AbstractModel
- AbstractWrapperModel
- AbstractSectionModel
- PPZ::LeafSectionModel
- Defined in:
- lib/doc/model/section/leaf.rb
Constant Summary collapse
- REG_EXP =
/^(\#{1,5}) (.+)/
Instance Attribute Summary collapse
-
#level ⇒ Object
Returns the value of attribute level.
-
#section_dom_id ⇒ Object
Returns the value of attribute section_dom_id.
-
#title ⇒ Object
Returns the value of attribute title.
Attributes inherited from AbstractModel
#father_model, #index, #left_model, #right_model
Class Method Summary collapse
Instance Method Summary collapse
- #get_nav_html ⇒ Object
-
#initialize(title, level) ⇒ LeafSectionModel
constructor
A new instance of LeafSectionModel.
- #to_html ⇒ Object
Methods inherited from AbstractSectionModel
Methods inherited from AbstractWrapperModel
Methods inherited from AbstractModel
Constructor Details
#initialize(title, level) ⇒ LeafSectionModel
Returns a new instance of LeafSectionModel.
4 5 6 7 8 9 |
# File 'lib/doc/model/section/leaf.rb', line 4 def initialize title, level raise TypeError unless title.is_a?(String) && level.is_a?(Integer) super() # 不可以省略括号 @title = transform_inline_element title @level = level end |
Instance Attribute Details
#level ⇒ Object
Returns the value of attribute level.
2 3 4 |
# File 'lib/doc/model/section/leaf.rb', line 2 def level @level end |
#section_dom_id ⇒ Object
Returns the value of attribute section_dom_id.
2 3 4 |
# File 'lib/doc/model/section/leaf.rb', line 2 def section_dom_id @section_dom_id end |
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/doc/model/section/leaf.rb', line 2 def title @title end |
Class Method Details
.from_line(line) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/doc/model/section/leaf.rb', line 12 def self.from_line line return nil unless REG_EXP.match(line) level = { 1 => 1, # 一个井号是 一级 5 => 3 # 五个井号是 三级 }[$1.size] || 2 # 其余都是 两级 PPZ::LeafSectionModel.new $2, level end |
Instance Method Details
#get_nav_html ⇒ Object
22 23 24 |
# File 'lib/doc/model/section/leaf.rb', line 22 def get_nav_html return "<li><a href=\"##{section_dom_id}\">#{@title}</a><ul>#{super}</ul></li>" end |
#to_html ⇒ Object
26 27 28 |
# File 'lib/doc/model/section/leaf.rb', line 26 def to_html "<section id=#{@section_dom_id}><h#{@level}>#{@title}</h#{@level}>#{super}</section>" end |