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?, #to_f, #to_i

Constructor Details

#initialize(obj) ⇒ BooleanParam

Returns a new instance of BooleanParam.



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

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



79
80
81
# File 'lib/compendium/param_types.rb', line 79

def !
  !value
end

#boolean?Boolean

Returns:

  • (Boolean)


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

def boolean?
  true
end

#valueObject



74
75
76
# File 'lib/compendium/param_types.rb', line 74

def value
  [true, false][self]
end