Class: MuchBoolean

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

Constant Summary collapse

FALSE_VALUES =
[
  nil,
  0, '0',
  false, 'false', 'False', 'FALSE', 'f', 'F',
  'no', 'No', 'NO', 'n', 'N'
].freeze
VERSION =
"0.1.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.



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

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

Instance Attribute Details

#actualObject (readonly)

Returns the value of attribute actual.



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

def actual
  @actual
end

#givenObject (readonly)

Returns the value of attribute given.



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

def given
  @given
end

Class Method Details

.convert(value) ⇒ Object



12
13
14
# File 'lib/much-boolean.rb', line 12

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

.one_zero(boolean) ⇒ Object



16
17
18
# File 'lib/much-boolean.rb', line 16

def self.one_zero(boolean)
  boolean ? 1 : 0
end

.t_f(boolean) ⇒ Object



32
33
34
# File 'lib/much-boolean.rb', line 32

def self.t_f(boolean)
  boolean ? 't' : 'f'
end

.T_F(boolean) ⇒ Object



36
37
38
# File 'lib/much-boolean.rb', line 36

def self.T_F(boolean)
  boolean ? 'T' : 'F'
end

.True_False(boolean) ⇒ Object



24
25
26
# File 'lib/much-boolean.rb', line 24

def self.True_False(boolean)
  boolean ? 'True' : 'False'
end

.true_false(boolean) ⇒ Object



20
21
22
# File 'lib/much-boolean.rb', line 20

def self.true_false(boolean)
  boolean ? 'true' : 'false'
end

.TRUE_FALSE(boolean) ⇒ Object



28
29
30
# File 'lib/much-boolean.rb', line 28

def self.TRUE_FALSE(boolean)
  boolean ? 'TRUE' : 'FALSE'
end

.Y_N(boolean) ⇒ Object



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

def self.Y_N(boolean)
  boolean ? 'Y' : 'N'
end

.y_n(boolean) ⇒ Object



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

def self.y_n(boolean)
  boolean ? 'y' : 'n'
end

.yes_no(boolean) ⇒ Object



40
41
42
# File 'lib/much-boolean.rb', line 40

def self.yes_no(boolean)
  boolean ? 'yes' : 'no'
end

.Yes_No(boolean) ⇒ Object



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

def self.Yes_No(boolean)
  boolean ? 'Yes' : 'No'
end

.YES_NO(boolean) ⇒ Object



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

def self.YES_NO(boolean)
  boolean ? 'YES' : 'NO'
end

Instance Method Details

#==(other_boolean) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/much-boolean.rb', line 67

def ==(other_boolean)
  if other_boolean.kind_of?(MuchBoolean)
    self.actual == other_boolean.actual
  else
    self.actual == other_boolean
  end
end