Class: Token::Resolver::Node::Text

Inherits:
Object
  • Object
show all
Defined in:
lib/token/resolver/node/text.rb

Overview

Represents plain text content (not a token).

Text nodes hold the literal string content between (or outside of) tokens. They are frozen after creation.

Examples:

text = Token::Resolver::Node::Text.new("Hello ")
text.to_s     # => "Hello "
text.content  # => "Hello "

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ Text

Returns a new instance of Text.

Parameters:

  • content (String)

    The text content



20
21
22
23
# File 'lib/token/resolver/node/text.rb', line 20

def initialize(content)
  @content = content.frozen? ? content : content.dup.freeze
  freeze
end

Instance Attribute Details

#contentString (readonly)

Returns The text content.

Returns:

  • (String)

    The text content



17
18
19
# File 'lib/token/resolver/node/text.rb', line 17

def content
  @content
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Equality based on content.

Parameters:

  • other (Object)

Returns:

  • (Boolean)


44
45
46
# File 'lib/token/resolver/node/text.rb', line 44

def eql?(other)
  other.is_a?(Text) && content == other.content
end

#hashInteger

Returns:

  • (Integer)


51
52
53
# File 'lib/token/resolver/node/text.rb', line 51

def hash
  [self.class, content].hash
end

#inspectString

Returns:

  • (String)


56
57
58
# File 'lib/token/resolver/node/text.rb', line 56

def inspect
  "#<#{self.class} #{content.inspect}>"
end

#text?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/token/resolver/node/text.rb', line 36

def text?
  true
end

#to_sString

Returns The text content.

Returns:

  • (String)

    The text content



26
27
28
# File 'lib/token/resolver/node/text.rb', line 26

def to_s
  @content
end

#token?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/token/resolver/node/text.rb', line 31

def token?
  false
end