Class: Hocon::Impl::Tokens::Substitution

Inherits:
Token
  • Object
show all
Defined in:
lib/hocon/impl/tokens.rb

Overview

This is not a Value, because it requires special processing

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(origin, optional, expression) ⇒ Substitution

Returns a new instance of Substitution.



250
251
252
253
254
# File 'lib/hocon/impl/tokens.rb', line 250

def initialize(origin, optional, expression)
  super(TokenType::SUBSTITUTION, origin)
  @optional = optional
  @value = expression
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



260
261
262
# File 'lib/hocon/impl/tokens.rb', line 260

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



280
281
282
# File 'lib/hocon/impl/tokens.rb', line 280

def ==(other)
  super(other) && other.value == @value
end

#can_equal(other) ⇒ Object



276
277
278
# File 'lib/hocon/impl/tokens.rb', line 276

def can_equal(other)
  other.is_a?(Substitution)
end

#hashObject



284
285
286
# File 'lib/hocon/impl/tokens.rb', line 284

def hash
  41 * (41 + super + @value.hash)
end

#optional?Boolean

Returns:

  • (Boolean)


256
257
258
# File 'lib/hocon/impl/tokens.rb', line 256

def optional?
  @optional
end

#to_sObject



268
269
270
271
272
273
274
# File 'lib/hocon/impl/tokens.rb', line 268

def to_s
  sb = StringIO.new
  value.each do |t|
    sb << t.to_s
  end
  "'${#{sb.to_s}}'"
end

#token_textObject



262
263
264
265
266
# File 'lib/hocon/impl/tokens.rb', line 262

def token_text
  sub_text = ""
  @value.each { |t| sub_text << t.token_text }
  "${" + (@optional ? "?" : "") + sub_text + "}"
end