Class: Luoma::Predicate

Inherits:
Expression show all
Defined in:
lib/luoma/expression.rb,
sig/luoma/expression.rbs

Instance Attribute Summary collapse

Attributes inherited from Expression

#span, #token

Instance Method Summary collapse

Methods inherited from Expression

#scope

Constructor Details

#initialize(token, value) ⇒ Predicate

(t_token, String) -> void

Parameters:

  • token (t_token)
  • value (String)


979
980
981
982
# File 'lib/luoma/expression.rb', line 979

def initialize(token, value)
  super(token)
  @value = value
end

Instance Attribute Details

#valueString (readonly)

Returns the value of attribute value.

Returns:

  • (String)


976
977
978
# File 'lib/luoma/expression.rb', line 976

def value
  @value
end

Instance Method Details

#childrenObject



1004
1005
1006
# File 'lib/luoma/expression.rb', line 1004

def children
  []
end

#evaluate(context) ⇒ Object

Signature:

  • (RenderContext) -> untyped



985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
# File 'lib/luoma/expression.rb', line 985

def evaluate(context)
  func = context.env.predicates[@value]

  if func.nil?
    if context.env.strict
      raise PredicateNotFoundError.new(
        "unknown predicate #{@value.inspect}",
        @token,
        context.template.source,
        context.template.name
      )
    end

    :nothing
  else
    PredicateFunction.new(@value, func)
  end
end

#to_sObject

Signature:

  • () -> String



1009
1010
1011
# File 'lib/luoma/expression.rb', line 1009

def to_s
  "#{@value}?"
end