Class: Rjq::AST::Format
Instance Attribute Summary collapse
-
#expression ⇒ Object
readonly
Returns the value of attribute expression.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from Node
Instance Method Summary collapse
- #eval(input, context) ⇒ Object
-
#initialize(name, expression = nil) ⇒ Format
constructor
A new instance of Format.
Methods inherited from Node
#assign_value, #invalid_path_message, #paths, #take, #with_source_span
Constructor Details
#initialize(name, expression = nil) ⇒ Format
Returns a new instance of Format.
238 239 240 241 |
# File 'lib/rjq/ast.rb', line 238 def initialize(name, expression = nil) @name = name @expression = expression end |
Instance Attribute Details
#expression ⇒ Object (readonly)
Returns the value of attribute expression.
236 237 238 |
# File 'lib/rjq/ast.rb', line 236 def expression @expression end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
236 237 238 |
# File 'lib/rjq/ast.rb', line 236 def name @name end |
Instance Method Details
#eval(input, context) ⇒ Object
243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/rjq/ast.rb', line 243 def eval(input, context) return Builtins.call(@name, input, context, []) unless @expression if @expression.is_a?(StringLiteral) && @expression.value.is_a?(Array) return @expression.value.reduce(['']) do |prefixes, (kind, value)| suffixes = format_segment(kind, value, input, context) prefixes.flat_map { |prefix| suffixes.map { |suffix| prefix + suffix } } end end @expression.eval(input, context).flat_map { |value| Builtins.call(@name, value, context, []) } end |