Class: Opto::Resolvers::Condition::HashCond

Inherits:
Object
  • Object
show all
Defined in:
lib/opto/resolvers/condition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group, options = {}) ⇒ HashCond


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/opto/resolvers/condition.rb', line 39

def initialize(group, options={})
  @group = group
  if options.has_key?(:else)
    @result = options[:else]
    @else = true
  elsif options.has_key?(:if) || options.has_key?(:elsif)
    @condition = options[:if] || options[:elsif]
    if options.has_key?(:then)
      @result = options[:then]
    else
      raise ArgumentError, "Invalid condition definition: #{options.inspect} (no 'then')"
    end
    @else = false
  else
    raise ArgumentError, "Invalid condition definition: #{options.inspect} (no 'if', 'elsif' or 'else')"
  end
end

Instance Attribute Details

#conditionObject (readonly)

Returns the value of attribute condition


35
36
37
# File 'lib/opto/resolvers/condition.rb', line 35

def condition
  @condition
end

#groupObject (readonly)

Returns the value of attribute group


37
38
39
# File 'lib/opto/resolvers/condition.rb', line 37

def group
  @group
end

#resultObject (readonly)

Returns the value of attribute result


36
37
38
# File 'lib/opto/resolvers/condition.rb', line 36

def result
  @result
end

Instance Method Details

#else?Boolean


57
58
59
# File 'lib/opto/resolvers/condition.rb', line 57

def else?
  @else
end

#true?Boolean


61
62
63
64
65
# File 'lib/opto/resolvers/condition.rb', line 61

def true?
  return true if else?
  return true if group.all_true?(condition)
  false
end