Class: MuchBoolean
- Inherits:
-
Object
- Object
- MuchBoolean
- Defined in:
- lib/much-boolean.rb,
lib/much-boolean/version.rb
Defined Under Namespace
Modules: Mapping
Constant Summary collapse
- FALSE_VALUES =
[ 0, '0', false, 'false', 'False', 'FALSE', 'f', 'F', 'no', 'No', 'NO', 'n', 'N' ].freeze
- VERSION =
"0.1.3"
Instance Attribute Summary collapse
-
#actual ⇒ Object
readonly
Returns the value of attribute actual.
-
#given ⇒ Object
readonly
Returns the value of attribute given.
Class Method Summary collapse
- .convert(value) ⇒ Object
- .one_zero(boolean) ⇒ Object
- .t_f(boolean) ⇒ Object
- .T_F(boolean) ⇒ Object
- .True_False(boolean) ⇒ Object
- .true_false(boolean) ⇒ Object
- .TRUE_FALSE(boolean) ⇒ Object
- .Y_N(boolean) ⇒ Object
- .y_n(boolean) ⇒ Object
- .yes_no(boolean) ⇒ Object
- .Yes_No(boolean) ⇒ Object
- .YES_NO(boolean) ⇒ Object
Instance Method Summary collapse
- #==(other_boolean) ⇒ Object
-
#initialize(given = nil) ⇒ MuchBoolean
constructor
A new instance of MuchBoolean.
Constructor Details
#initialize(given = nil) ⇒ MuchBoolean
Returns a new instance of MuchBoolean.
30 31 32 33 |
# File 'lib/much-boolean.rb', line 30 def initialize(given = nil) @given = given @actual = self.class.convert(@given) end |
Instance Attribute Details
#actual ⇒ Object (readonly)
Returns the value of attribute actual.
28 29 30 |
# File 'lib/much-boolean.rb', line 28 def actual @actual end |
#given ⇒ Object (readonly)
Returns the value of attribute given.
28 29 30 |
# File 'lib/much-boolean.rb', line 28 def given @given end |
Class Method Details
.convert(value) ⇒ Object
11 12 13 14 |
# File 'lib/much-boolean.rb', line 11 def self.convert(value) return nil if value.to_s.empty? # covers `nil` and `""` !FALSE_VALUES.include?(value) end |
.one_zero(boolean) ⇒ Object
16 |
# File 'lib/much-boolean.rb', line 16 def self.one_zero(boolean); Mapping.new(boolean, 1, 0); end |
.t_f(boolean) ⇒ Object
20 |
# File 'lib/much-boolean.rb', line 20 def self.t_f(boolean); Mapping.new(boolean, 't', 'f'); end |
.T_F(boolean) ⇒ Object
21 |
# File 'lib/much-boolean.rb', line 21 def self.T_F(boolean); Mapping.new(boolean, 'T', 'F'); end |
.True_False(boolean) ⇒ Object
18 |
# File 'lib/much-boolean.rb', line 18 def self.True_False(boolean); Mapping.new(boolean, 'True', 'False'); end |
.true_false(boolean) ⇒ Object
17 |
# File 'lib/much-boolean.rb', line 17 def self.true_false(boolean); Mapping.new(boolean, 'true', 'false'); end |
.TRUE_FALSE(boolean) ⇒ Object
19 |
# File 'lib/much-boolean.rb', line 19 def self.TRUE_FALSE(boolean); Mapping.new(boolean, 'TRUE', 'FALSE'); end |
.Y_N(boolean) ⇒ Object
26 |
# File 'lib/much-boolean.rb', line 26 def self.Y_N(boolean); Mapping.new(boolean, 'Y', 'N'); end |
.y_n(boolean) ⇒ Object
25 |
# File 'lib/much-boolean.rb', line 25 def self.y_n(boolean); Mapping.new(boolean, 'y', 'n'); end |
.yes_no(boolean) ⇒ Object
22 |
# File 'lib/much-boolean.rb', line 22 def self.yes_no(boolean); Mapping.new(boolean, 'yes', 'no'); end |
Instance Method Details
#==(other_boolean) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/much-boolean.rb', line 35 def ==(other_boolean) if other_boolean.kind_of?(MuchBoolean) self.actual == other_boolean.actual else self.actual == other_boolean end end |