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.



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

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.



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

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



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

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

#can_equal(other) ⇒ Object



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

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

#hashObject



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

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

#optional?Boolean

Returns:

  • (Boolean)


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

def optional?
  @optional
end

#to_sObject



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

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

#token_textObject



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

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