Class: Factbase::Boolean

Inherits:
Object
  • Object
show all
Defined in:
lib/factbase/terms/boolean.rb

Overview

Boolean value checker.

Instance Method Summary collapse

Constructor Details

#initialize(val, from) ⇒ Boolean

Constructor.

Parameters:

  • val (Object)

    The value to check

  • from (Object)

    The source of the value (for error messages)

Raises:

  • (RuntimeError)

    If value is not a boolean



14
15
16
17
# File 'lib/factbase/terms/boolean.rb', line 14

def initialize(val, from)
  @val = val
  @from = from
end

Instance Method Details

#bool?Boolean

Returns The boolean value.

Returns:

Raises:

  • (RuntimeError)

    If value is not a boolean



21
22
23
24
25
26
27
# File 'lib/factbase/terms/boolean.rb', line 21

def bool?
  val = @val
  val = val[0] if val.respond_to?(:each)
  return false if val.nil?
  return val if val.is_a?(TrueClass) || val.is_a?(FalseClass)
  raise "Boolean is expected, while #{val.class} received from #{@from}"
end