Class: Prosereflect::Schema::TextNode
- Inherits:
-
Node
- Object
- Node
- Prosereflect::Schema::TextNode
show all
- Defined in:
- lib/prosereflect/schema/node.rb
Overview
Lightweight TextNode for schema validation
Instance Attribute Summary collapse
Attributes inherited from Node
#attrs, #content, #marks, #type
Instance Method Summary
collapse
Methods inherited from Node
#descendants, from_json, #is_atom, #is_block, #is_inline, #is_leaf, #is_text, #nodes_between, #same_marks?, #same_markup?, #text?, #with_text
Constructor Details
#initialize(type:, attrs: {}, text: "", marks: []) ⇒ TextNode
Returns a new instance of TextNode.
200
201
202
203
|
# File 'lib/prosereflect/schema/node.rb', line 200
def initialize(type:, attrs: {}, text: "", marks: [])
super(type: type, attrs: { text: text }, content: Fragment.empty, marks: marks)
@text = text
end
|
Instance Attribute Details
#text ⇒ Object
Returns the value of attribute text.
198
199
200
|
# File 'lib/prosereflect/schema/node.rb', line 198
def text
@text
end
|
Instance Method Details
#cut(from = 0, to = nil) ⇒ Object
213
214
215
216
217
|
# File 'lib/prosereflect/schema/node.rb', line 213
def cut(from = 0, to = nil)
to ||= @text.length
TextNode.new(type: @type, attrs: { text: @text[from...to] },
text: @text[from...to], marks: @marks)
end
|
#eq?(other) ⇒ Boolean
219
220
221
222
223
|
# File 'lib/prosereflect/schema/node.rb', line 219
def eq?(other)
return false unless other.is_a?(TextNode)
@text == other.text && super
end
|
#node_size ⇒ Object
205
206
207
|
# File 'lib/prosereflect/schema/node.rb', line 205
def node_size
@text.length + 1
end
|
#text_content ⇒ Object
209
210
211
|
# File 'lib/prosereflect/schema/node.rb', line 209
def text_content
@text
end
|
#to_h ⇒ Object
225
226
227
228
229
|
# File 'lib/prosereflect/schema/node.rb', line 225
def to_h
result = { "type" => @type.name, "text" => @text }
result["marks"] = @marks.map(&:to_h) if @marks && !@marks.empty?
result
end
|
#to_s ⇒ Object
231
232
233
|
# File 'lib/prosereflect/schema/node.rb', line 231
def to_s
"<TextNode \"#{@text[0, 20]}\">"
end
|