Class: Prosereflect::Paragraph
- Defined in:
- lib/prosereflect/paragraph.rb
Constant Summary collapse
- PM_TYPE =
"paragraph"
Class Method Summary collapse
Instance Method Summary collapse
-
#add_hard_break(marks = nil) ⇒ Object
Add a hard break to the paragraph.
-
#add_text(text, marks = nil) ⇒ Object
Add text to the paragraph.
-
#initialize(params = {}) ⇒ Paragraph
constructor
A new instance of Paragraph.
- #text_content ⇒ Object
- #text_nodes ⇒ Object
Methods inherited from Node
#add_child, #copy, #cut, #descendants, #eq?, #find_all, #find_children, #find_first, #marks, #marks=, #node, #node_size, #nodes_between, #parse_content, #process_attrs_data, #raw_marks, #resolve, #text?, #to_h, #to_yaml
Constructor Details
#initialize(params = {}) ⇒ Paragraph
Returns a new instance of Paragraph.
18 19 20 21 |
# File 'lib/prosereflect/paragraph.rb', line 18 def initialize(params = {}) super self.content ||= [] end |
Class Method Details
.create(attrs = nil) ⇒ Object
23 24 25 |
# File 'lib/prosereflect/paragraph.rb', line 23 def self.create(attrs = nil) new(attrs: attrs) end |
Instance Method Details
#add_hard_break(marks = nil) ⇒ Object
Add a hard break to the paragraph
53 54 55 56 57 |
# File 'lib/prosereflect/paragraph.rb', line 53 def add_hard_break(marks = nil) hard_break = HardBreak.create(marks) add_child(hard_break) hard_break end |
#add_text(text, marks = nil) ⇒ Object
Add text to the paragraph
44 45 46 47 48 49 50 |
# File 'lib/prosereflect/paragraph.rb', line 44 def add_text(text, marks = nil) return if text.nil? || text.empty? text_node = Text.create(text, marks) add_child(text_node) text_node end |
#text_content ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/prosereflect/paragraph.rb', line 33 def text_content return "" unless content result = "" content.each do |node| result += node.text_content end result end |
#text_nodes ⇒ Object
27 28 29 30 31 |
# File 'lib/prosereflect/paragraph.rb', line 27 def text_nodes return [] unless content content.grep(Text) end |