Class: GhostWheel::Expression::Transform

Inherits:
GhostWheel::Expression show all
Defined in:
lib/ghost_wheel/expression/transform.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from GhostWheel::Expression

#parse

Constructor Details

#initialize(expression, &transformer) ⇒ Transform

Returns a new instance of Transform.


6
7
8
9
# File 'lib/ghost_wheel/expression/transform.rb', line 6

def initialize(expression, &transformer)
  @expression  = expression
  @transformer = transformer
end

Instance Attribute Details

#expressionObject (readonly)

Returns the value of attribute expression


11
12
13
# File 'lib/ghost_wheel/expression/transform.rb', line 11

def expression
  @expression
end

#transformerObject (readonly)

Returns the value of attribute transformer


11
12
13
# File 'lib/ghost_wheel/expression/transform.rb', line 11

def transformer
  @transformer
end

Instance Method Details

#==(other) ⇒ Object


23
24
25
26
27
# File 'lib/ghost_wheel/expression/transform.rb', line 23

def ==(other)
  super                            and
  @expression  == other.expression and
  @transformer == other.transformer
end

#uncached_parse(scanner, cache) ⇒ Object


13
14
15
16
17
18
19
20
21
# File 'lib/ghost_wheel/expression/transform.rb', line 13

def uncached_parse(scanner, cache)
  result = @expression.parse(scanner, cache)
  if result.is_a? FailedParseResult
    result
  else
    value = result.is_a?(ParseResult) ? result.value : result
    ParseResult.new(@transformer[value])
  end
end