Class: Rjq::AST::StringLiteral

Inherits:
Node
  • Object
show all
Defined in:
lib/rjq/ast.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#source_span

Instance Method Summary collapse

Methods inherited from Node

#assign_value, #invalid_path_message, #paths, #take, #with_source_span

Constructor Details

#initialize(value) ⇒ StringLiteral

Returns a new instance of StringLiteral.



212
213
214
# File 'lib/rjq/ast.rb', line 212

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



210
211
212
# File 'lib/rjq/ast.rb', line 210

def value
  @value
end

Instance Method Details

#eval(input, context) ⇒ Object



216
217
218
219
220
221
222
223
# File 'lib/rjq/ast.rb', line 216

def eval(input, context)
  return [@value] if @value.is_a?(String)

  @value.reduce(['']) do |prefixes, (kind, value)|
    suffixes = eval_segment(kind, value, input, context)
    prefixes.flat_map { |prefix| suffixes.map { |suffix| prefix + suffix } }
  end
end