Class: Prosereflect::Text
- Defined in:
- lib/prosereflect/text.rb
Constant Summary collapse
- PM_TYPE =
"text"
Class Method Summary collapse
Instance Method Summary collapse
-
#cut(from = 0, to = nil) ⇒ Object
Return a copy of this text node with content restricted to range.
-
#eq?(other) ⇒ Boolean
Check equality with another text node.
-
#node_size ⇒ Object
Text node size is text length + 1 (for the opening token).
-
#text? ⇒ Boolean
Text nodes are text nodes.
- #text_content ⇒ Object
-
#to_h ⇒ Object
Override the to_h method to include the text attribute.
Methods inherited from Node
#add_child, #copy, #descendants, #find_all, #find_children, #find_first, #initialize, #marks, #marks=, #node, #nodes_between, #parse_content, #process_attrs_data, #raw_marks, #resolve, #to_yaml
Constructor Details
This class inherits a constructor from Prosereflect::Node
Class Method Details
.create(text = "", marks = nil) ⇒ Object
18 19 20 |
# File 'lib/prosereflect/text.rb', line 18 def self.create(text = "", marks = nil) new(text: text, marks: marks) end |
Instance Method Details
#cut(from = 0, to = nil) ⇒ Object
Return a copy of this text node with content restricted to range
37 38 39 40 41 |
# File 'lib/prosereflect/text.rb', line 37 def cut(from = 0, to = nil) txt = text || "" to ||= txt.length self.class.new(text: txt[from...to], marks: raw_marks) end |
#eq?(other) ⇒ Boolean
Check equality with another text node
44 45 46 47 48 |
# File 'lib/prosereflect/text.rb', line 44 def eq?(other) return false unless other.is_a?(self.class) text == other.text && to_h == other.to_h end |
#node_size ⇒ Object
Text node size is text length + 1 (for the opening token)
27 28 29 |
# File 'lib/prosereflect/text.rb', line 27 def node_size (text || "").length + 1 end |
#text? ⇒ Boolean
Text nodes are text nodes
32 33 34 |
# File 'lib/prosereflect/text.rb', line 32 def text? true end |
#text_content ⇒ Object
22 23 24 |
# File 'lib/prosereflect/text.rb', line 22 def text_content text || "" end |
#to_h ⇒ Object
Override the to_h method to include the text attribute
51 52 53 54 55 |
# File 'lib/prosereflect/text.rb', line 51 def to_h result = super result["text"] = text result end |