Class: Prosereflect::Heading
- Inherits:
-
Node
- Object
- Lutaml::Model::Serializable
- Node
- Prosereflect::Heading
show all
- Defined in:
- lib/prosereflect/heading.rb
Constant Summary
collapse
- PM_TYPE =
'heading'
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Node
#add_child, #find_all, #find_children, #find_first, #marks, #marks=, #parse_content, #process_attrs_data, #raw_marks, #to_yaml
Constructor Details
#initialize(params = {}) ⇒ Heading
Returns a new instance of Heading.
21
22
23
24
25
26
27
28
29
|
# File 'lib/prosereflect/heading.rb', line 21
def initialize(params = {})
super
self.content ||= []
return unless params[:attrs]
@level = params[:attrs]['level']
end
|
Class Method Details
.create(attrs = nil) ⇒ Object
31
32
33
|
# File 'lib/prosereflect/heading.rb', line 31
def self.create(attrs = nil)
new(attrs: attrs)
end
|
Instance Method Details
#add_text(text) ⇒ Object
51
52
53
54
55
|
# File 'lib/prosereflect/heading.rb', line 51
def add_text(text)
text_node = Text.new(text: text)
add_child(text_node)
text_node
end
|
#level ⇒ Object
41
42
43
|
# File 'lib/prosereflect/heading.rb', line 41
def level
@level || attrs&.[]('level')
end
|
#level=(value) ⇒ Object
35
36
37
38
39
|
# File 'lib/prosereflect/heading.rb', line 35
def level=(value)
@level = value
self.attrs ||= {}
attrs['level'] = value
end
|
#text_content ⇒ Object
45
46
47
48
49
|
# File 'lib/prosereflect/heading.rb', line 45
def text_content
return '' unless content
content.map(&:text_content).join
end
|
#to_h ⇒ Object
57
58
59
60
61
62
|
# File 'lib/prosereflect/heading.rb', line 57
def to_h
result = super
result['attrs'] ||= {}
result['attrs']['level'] = level if level
result
end
|