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



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

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



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

def content
  @content
end

Instance Method Details

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

Equality based on content.

Parameters:

  • other (Object)

Returns:

  • (Boolean)


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

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

#hashInteger

Returns:

  • (Integer)


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

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

#inspectString

Returns:

  • (String)


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

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

#text?Boolean

Returns:

  • (Boolean)


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

def text?
  true
end

#to_sString

Returns The text content.

Returns:

  • (String)

    The text content



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

def to_s
  @content
end

#token?Boolean

Returns:

  • (Boolean)


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

def token?
  false
end