Class: Compendium::BooleanParam

Inherits:
Param
  • Object
show all
Defined in:
lib/compendium/param_types.rb

Instance Method Summary collapse

Methods inherited from Param

#==, #date?, #dropdown?, #nil?, #radio?, #scalar?

Constructor Details

#initialize(obj) ⇒ BooleanParam

Returns a new instance of BooleanParam.



56
57
58
59
60
# File 'lib/compendium/param_types.rb', line 56

def initialize(obj, *)
  # If given 0, 1, or a version thereof (ie. "0"), pass it along
  return super obj.to_i if obj.numeric? and (0..1).cover?(obj.to_i)
  super !!obj ? 0 : 1
end

Instance Method Details

#!Object

When negating a BooleanParam, use the value instead



71
72
73
# File 'lib/compendium/param_types.rb', line 71

def !
  !value
end

#boolean?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/compendium/param_types.rb', line 62

def boolean?
  true
end

#valueObject



66
67
68
# File 'lib/compendium/param_types.rb', line 66

def value
  [true, false][self]
end