Class: Gloo::Core::Op

Inherits:
Object
  • Object
show all
Defined in:
lib/gloo/core/op.rb

Class Method Summary collapse

Class Method Details

.create_op(token) ⇒ Object

Create the operator for the given token.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/gloo/core/op.rb', line 34

def self.create_op( token )
  case token
    when Gloo::Expr::OpPlus::SYMBOL then Gloo::Expr::OpPlus.new
    when Gloo::Expr::OpMinus::SYMBOL then Gloo::Expr::OpMinus.new
    when Gloo::Expr::OpMult::SYMBOL then Gloo::Expr::OpMult.new
    when Gloo::Expr::OpDiv::SYMBOL then Gloo::Expr::OpDiv.new
    when Gloo::Expr::OpEq::SYMBOL then return Gloo::Expr::OpEq.new
    when Gloo::Expr::OpEq::ALT_SYMBOL then return Gloo::Expr::OpEq.new
    when Gloo::Expr::OpIneq::SYMBOL then return Gloo::Expr::OpIneq.new
    when Gloo::Expr::OpGt::SYMBOL then return Gloo::Expr::OpGt.new
    when Gloo::Expr::OpLt::SYMBOL then return Gloo::Expr::OpLt.new
    when Gloo::Expr::OpGteq::SYMBOL then return Gloo::Expr::OpGteq.new
    when Gloo::Expr::OpLteq::SYMBOL then return Gloo::Expr::OpLteq.new
  else return default_op
  end
end

.default_opObject

Get the default operator (+).



54
55
56
# File 'lib/gloo/core/op.rb', line 54

def self.default_op
  return Gloo::Expr::OpPlus.new
end

.op?(token) ⇒ Boolean

Is the token an operator?

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gloo/core/op.rb', line 15

def self.op?( token )
  return [ 
    Gloo::Expr::OpPlus::SYMBOL,
    Gloo::Expr::OpMinus::SYMBOL,
    Gloo::Expr::OpMult::SYMBOL,
    Gloo::Expr::OpDiv::SYMBOL,
    Gloo::Expr::OpEq::SYMBOL,
    Gloo::Expr::OpEq::ALT_SYMBOL,
    Gloo::Expr::OpIneq::SYMBOL,
    Gloo::Expr::OpGt::SYMBOL,
    Gloo::Expr::OpLt::SYMBOL,
    Gloo::Expr::OpGteq::SYMBOL,
    Gloo::Expr::OpLteq::SYMBOL
    ].include?( token.strip )
end