Class: MuchBoolean

Inherits:
Object
  • Object
show all
Defined in:
lib/much-boolean.rb,
lib/much-boolean/version.rb

Defined Under Namespace

Modules: Mapping

Constant Summary collapse

FALSE_VALUES =
[
  nil,
  "",
  :"",
  0,
  "0",
  :"0",
  false,
  "f",
  :f,
  "F",
  :F,
  "false",
  :false,
  "False",
  :False,
  "FALSE",
  :FALSE,
  "off",
  :off,
  "Off",
  :Off,
  "OFF",
  :OFF,
  "n",
  :n,
  "N",
  :N,
  "no",
  :no,
  "No",
  :No,
  "NO",
  :NO,
].freeze
VERSION =
"0.2.1"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(given = nil) ⇒ MuchBoolean

Returns a new instance of MuchBoolean.



105
106
107
108
# File 'lib/much-boolean.rb', line 105

def initialize(given = nil)
  @given  = given
  @actual = self.class.convert(@given)
end

Instance Attribute Details

#actualObject (readonly)

Returns the value of attribute actual.



103
104
105
# File 'lib/much-boolean.rb', line 103

def actual
  @actual
end

#givenObject (readonly)

Returns the value of attribute given.



103
104
105
# File 'lib/much-boolean.rb', line 103

def given
  @given
end

Class Method Details

.convert(value) ⇒ Object



43
44
45
# File 'lib/much-boolean.rb', line 43

def self.convert(value)
  !FALSE_VALUES.include?(value)
end

.On_Off(boolean) ⇒ Object



75
76
77
# File 'lib/much-boolean.rb', line 75

def self.On_Off(boolean)
  Mapping.new(boolean, "On", "Off")
end

.ON_OFF(boolean) ⇒ Object



79
80
81
# File 'lib/much-boolean.rb', line 79

def self.ON_OFF(boolean)
  Mapping.new(boolean, "ON", "OFF")
end

.on_off(boolean) ⇒ Object



71
72
73
# File 'lib/much-boolean.rb', line 71

def self.on_off(boolean)
  Mapping.new(boolean, "on", "off")
end

.one_zero(boolean) ⇒ Object



47
48
49
# File 'lib/much-boolean.rb', line 47

def self.one_zero(boolean)
  Mapping.new(boolean, 1, 0)
end

.T_F(boolean) ⇒ Object



55
56
57
# File 'lib/much-boolean.rb', line 55

def self.T_F(boolean)
  Mapping.new(boolean, "T", "F")
end

.t_f(boolean) ⇒ Object



51
52
53
# File 'lib/much-boolean.rb', line 51

def self.t_f(boolean)
  Mapping.new(boolean, "t", "f")
end

.TRUE_FALSE(boolean) ⇒ Object



67
68
69
# File 'lib/much-boolean.rb', line 67

def self.TRUE_FALSE(boolean)
  Mapping.new(boolean, "TRUE", "FALSE")
end

.True_False(boolean) ⇒ Object



63
64
65
# File 'lib/much-boolean.rb', line 63

def self.True_False(boolean)
  Mapping.new(boolean, "True", "False")
end

.true_false(boolean) ⇒ Object



59
60
61
# File 'lib/much-boolean.rb', line 59

def self.true_false(boolean)
  Mapping.new(boolean, "true", "false")
end

.y_n(boolean) ⇒ Object



83
84
85
# File 'lib/much-boolean.rb', line 83

def self.y_n(boolean)
  Mapping.new(boolean, "y", "n")
end

.Y_N(boolean) ⇒ Object



87
88
89
# File 'lib/much-boolean.rb', line 87

def self.Y_N(boolean)
  Mapping.new(boolean, "Y", "N")
end

.yes_no(boolean) ⇒ Object



91
92
93
# File 'lib/much-boolean.rb', line 91

def self.yes_no(boolean)
  Mapping.new(boolean, "yes", "no")
end

.Yes_No(boolean) ⇒ Object



95
96
97
# File 'lib/much-boolean.rb', line 95

def self.Yes_No(boolean)
  Mapping.new(boolean, "Yes", "No")
end

.YES_NO(boolean) ⇒ Object



99
100
101
# File 'lib/much-boolean.rb', line 99

def self.YES_NO(boolean)
  Mapping.new(boolean, "YES", "NO")
end

Instance Method Details

#==(other) ⇒ Object



110
111
112
113
114
115
116
# File 'lib/much-boolean.rb', line 110

def ==(other)
  actual == if other.is_a?(MuchBoolean)
    other.actual
  else
    other
  end
end