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, #find_all, #find_children, #find_first, #marks, #marks=, #parse_content, #process_attrs_data, #raw_marks, #to_h, #to_yaml
Constructor Details
#initialize(params = {}) ⇒ Paragraph
Returns a new instance of Paragraph.
20 21 22 23 |
# File 'lib/prosereflect/paragraph.rb', line 20 def initialize(params = {}) super self.content ||= [] end |
Class Method Details
.create(attrs = nil) ⇒ Object
25 26 27 |
# File 'lib/prosereflect/paragraph.rb', line 25 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
55 56 57 58 59 |
# File 'lib/prosereflect/paragraph.rb', line 55 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
46 47 48 49 50 51 52 |
# File 'lib/prosereflect/paragraph.rb', line 46 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
35 36 37 38 39 40 41 42 43 |
# File 'lib/prosereflect/paragraph.rb', line 35 def text_content return '' unless content result = '' content.each do |node| result += node.text_content end result end |
#text_nodes ⇒ Object
29 30 31 32 33 |
# File 'lib/prosereflect/paragraph.rb', line 29 def text_nodes return [] unless content content.select { |node| node.is_a?(Text) } end |