Class: Claus

Inherits:
Object
  • Object
show all
Defined in:
lib/claus.rb

Overview

Santa Claus tells ya if you’re naughty or nice.

Examples:

claus = Claus.new(foo: 1, bar: 2)
claus.match(foo: 1, bar: 2)           #=> true
claus.match(foo: 1, bar: 3)           #=> false
claus.match(foo: 1, bar: 2, baz: 3)   #=> true

claus = Claus.new(foo: 1, bar: 1..2)
claus.match(foo: 1, bar: 2)           #=> true

claus = Claus.new([{foo:1}, {bar:2}])
claus.match?(foo: 1)                  #=> true
claus.match?(bar: 2)                  #=> true
claus.match?(baz: 3)                  #=> false

Defined Under Namespace

Modules: AST

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expression) ⇒ Claus

Returns a new instance of Claus.



20
21
22
# File 'lib/claus.rb', line 20

def initialize expression
  @ast = compile(expression)
end

Instance Attribute Details

#astObject (readonly)

Returns the value of attribute ast.



18
19
20
# File 'lib/claus.rb', line 18

def ast
  @ast
end

Instance Method Details

#match?(value) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/claus.rb', line 24

def match? value
  @ast.match?(value)
end