Class: Kotoshu::Documents::TextNode
- Inherits:
-
Object
- Object
- Kotoshu::Documents::TextNode
- Defined in:
- lib/kotoshu/documents/document.rb
Overview
Text node abstraction for structured documents.
Represents a span of text in a document with location information. Used for spell checking individual text elements in structured formats.
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#node_path ⇒ Object
readonly
Returns the value of attribute node_path.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Check if this equals another text node.
-
#hash ⇒ Integer
Hash code for hash table usage.
-
#initialize(text, location:, node_path: nil) ⇒ TextNode
constructor
Create a new text node.
-
#to_s ⇒ String
(also: #inspect)
String representation.
-
#words ⇒ Array<String>
Get words from this text node.
Constructor Details
#initialize(text, location:, node_path: nil) ⇒ TextNode
Create a new text node.
24 25 26 27 28 29 |
# File 'lib/kotoshu/documents/document.rb', line 24 def initialize(text, location:, node_path: nil) @text = text @location = location @node_path = node_path freeze end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
17 18 19 |
# File 'lib/kotoshu/documents/document.rb', line 17 def location @location end |
#node_path ⇒ Object (readonly)
Returns the value of attribute node_path.
17 18 19 |
# File 'lib/kotoshu/documents/document.rb', line 17 def node_path @node_path end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
17 18 19 |
# File 'lib/kotoshu/documents/document.rb', line 17 def text @text end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Check if this equals another text node.
42 43 44 45 46 |
# File 'lib/kotoshu/documents/document.rb', line 42 def ==(other) return false unless other.is_a?(TextNode) @text == other.text && @location == other.location end |
#hash ⇒ Integer
Hash code for hash table usage.
52 53 54 |
# File 'lib/kotoshu/documents/document.rb', line 52 def hash [@text, @location].hash end |
#to_s ⇒ String Also known as: inspect
String representation.
59 60 61 62 63 64 65 |
# File 'lib/kotoshu/documents/document.rb', line 59 def to_s if @location.line_column? "#{@location}: #{@text}" else @text end end |
#words ⇒ Array<String>
Get words from this text node.
34 35 36 |
# File 'lib/kotoshu/documents/document.rb', line 34 def words @text.split end |