Class: Musterb::Evaluator

Inherits:
Object
  • Object
show all
Includes:
ExtractValues
Defined in:
lib/musterb/evaluator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ExtractValues

#[], #chain, new_context, #value

Constructor Details

#initialize(context) ⇒ Evaluator

Returns a new instance of Evaluator.



6
7
8
# File 'lib/musterb/evaluator.rb', line 6

def initialize(context)
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



4
5
6
# File 'lib/musterb/evaluator.rb', line 4

def context
  @context
end

Instance Method Details

#block_if(value) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/musterb/evaluator.rb', line 14

def block_if(value)
  return if is_falsy? value

  case value
  when Hash
    switch_context(value) { |v| yield v }
  when Enumerable
    value.each { |e| switch_context(e) { |v| yield v } }
  else
    switch_context(value) { |v| yield v }
  end
end

#block_unless(value) ⇒ Object



27
28
29
# File 'lib/musterb/evaluator.rb', line 27

def block_unless(value)
  yield if is_falsy? value
end

#currentObject



10
11
12
# File 'lib/musterb/evaluator.rb', line 10

def current
  @context.value
end