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?

Constructor Details

#initialize(obj) ⇒ BooleanParam

Returns a new instance of BooleanParam.



44
45
46
47
48
# File 'lib/compendium/param_types.rb', line 44

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



59
60
61
# File 'lib/compendium/param_types.rb', line 59

def !
  !value
end

#boolean?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/compendium/param_types.rb', line 50

def boolean?
  true
end

#valueObject



54
55
56
# File 'lib/compendium/param_types.rb', line 54

def value
  [true, false][self]
end