much-boolean 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 48aafb38b7e679d55b28931ecdd3faaecdf9002b
4
- data.tar.gz: c4e0ffce78e57e3dc90c99cc057c100ba62cc39a
5
2
  SHA512:
6
- metadata.gz: b8327489713a0b0ddece4c7ba41977d780f3050c532d6a7fdc4e9c85a89544797ec2ef0bb62f1255f56ccf1aec62d11ac65e3d8b7aaad6a7f36df53d37dd5db0
7
- data.tar.gz: f9fafdee5f32d913d492ff660e6c5c68fbead9788f9055c8cd88ba73717eb53d094e65649fa96dc7b37b02de7b22bcb5bec77aa664fbfe1a839c0c5439789848
3
+ metadata.gz: d7064dc39084f79826e0555d371eb3dff5d1041aac760369bc4ea85acf28910081feddd25574b26ca4785acec3d723bd317087cae48eab74e9a91970c5a582bb
4
+ data.tar.gz: 5efcbb6b7d60486a93dcb3a7c5dcbab5f4bc800ddfeb39ecf04db4cc279cf78010027f92462b127d502890279c08f3dd76440e971aed705b2b3c9aeebed4b3c2
5
+ SHA1:
6
+ metadata.gz: 4ee0638be5734277870e64c9702bb19283db49ec
7
+ data.tar.gz: 0da0868bd99bd239a704225c211195dd259ec73d
data/README.md CHANGED
@@ -11,6 +11,8 @@ MuchBoolean::FALSE_VALUES # => [ nil, 0, "0",
11
11
  # "no", "No", "NO", "n", "N"
12
12
  # ]
13
13
 
14
+ # convert human-friendly representative values to actual booleans
15
+
14
16
  # nil, zero/one type values
15
17
  MuchBoolean.convert(nil) # => false
16
18
  MuchBoolean.convert(0) # => false
@@ -53,7 +55,38 @@ MuchBoolean.convert(Time.now) # => true
53
55
 
54
56
 
55
57
 
56
- # create instances to track given values and the actually boolean values they map to
58
+ # convert actual booleans back to human-friendly representative values
59
+
60
+ MuchBoolean.one_zero(true) # => 1
61
+ MuchBoolean.one_zero(false) # => 0
62
+ MuchBoolean.one_zero(true).to_s # => '1'
63
+ MuchBoolean.one_zero(false).to_s # => '0'
64
+
65
+ MuchBoolean.true_false(true) # => 'true'
66
+ MuchBoolean.true_false(false) # => 'false'
67
+ MuchBoolean.True_False(true) # => 'True'
68
+ MuchBoolean.True_False(false) # => 'False'
69
+ MuchBoolean.TRUE_FALSE(true) # => 'TRUE'
70
+ MuchBoolean.TRUE_FALSE(false) # => 'FALSE'
71
+ MuchBoolean.t_f(true) # => 't'
72
+ MuchBoolean.t_f(false) # => 'f'
73
+ MuchBoolean.T_F(true) # => 'T'
74
+ MuchBoolean.T_F(false) # => 'F'
75
+
76
+ MuchBoolean.yes_no(true) # => 'yes'
77
+ MuchBoolean.yes_no(false) # => 'no'
78
+ MuchBoolean.Yes_No(true) # => 'Yes'
79
+ MuchBoolean.Yes_No(false) # => 'No'
80
+ MuchBoolean.YES_NO(true) # => 'YES'
81
+ MuchBoolean.YES_NO(false) # => 'NO'
82
+ MuchBoolean.y_n(true) # => 'y'
83
+ MuchBoolean.y_n(false) # => 'n'
84
+ MuchBoolean.Y_N(true) # => 'Y'
85
+ MuchBoolean.Y_N(false) # => 'N'
86
+
87
+
88
+
89
+ # create instances to track given human-friendly values and the boolean values they map to
57
90
 
58
91
  bool = MuchBoolean.new
59
92
  bool.given # => nil
@@ -1,3 +1,3 @@
1
1
  class MuchBoolean
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/much-boolean.rb CHANGED
@@ -13,6 +13,50 @@ class MuchBoolean
13
13
  !FALSE_VALUES.include?(value)
14
14
  end
15
15
 
16
+ def self.one_zero(boolean)
17
+ boolean ? 1 : 0
18
+ end
19
+
20
+ def self.true_false(boolean)
21
+ boolean ? 'true' : 'false'
22
+ end
23
+
24
+ def self.True_False(boolean)
25
+ boolean ? 'True' : 'False'
26
+ end
27
+
28
+ def self.TRUE_FALSE(boolean)
29
+ boolean ? 'TRUE' : 'FALSE'
30
+ end
31
+
32
+ def self.t_f(boolean)
33
+ boolean ? 't' : 'f'
34
+ end
35
+
36
+ def self.T_F(boolean)
37
+ boolean ? 'T' : 'F'
38
+ end
39
+
40
+ def self.yes_no(boolean)
41
+ boolean ? 'yes' : 'no'
42
+ end
43
+
44
+ def self.Yes_No(boolean)
45
+ boolean ? 'Yes' : 'No'
46
+ end
47
+
48
+ def self.YES_NO(boolean)
49
+ boolean ? 'YES' : 'NO'
50
+ end
51
+
52
+ def self.y_n(boolean)
53
+ boolean ? 'y' : 'n'
54
+ end
55
+
56
+ def self.Y_N(boolean)
57
+ boolean ? 'Y' : 'N'
58
+ end
59
+
16
60
  attr_reader :given, :actual
17
61
 
18
62
  def initialize(given = nil)
@@ -7,7 +7,10 @@ class MuchBoolean
7
7
  desc "MuchBoolean"
8
8
  subject{ MuchBoolean }
9
9
 
10
- should have_imeth :convert
10
+ should have_imeths :convert
11
+ should have_imeths :one_zero
12
+ should have_imeths :true_false, :True_False, :TRUE_FALSE, :t_f, :T_F
13
+ should have_imeths :yes_no, :Yes_No, :YES_NO, :y_n, :Y_N
11
14
 
12
15
  should "know its false values" do
13
16
  exp = [
@@ -65,6 +68,62 @@ class MuchBoolean
65
68
  end
66
69
  end
67
70
 
71
+ should "encode booleans as ones and zeros" do
72
+ assert_equal 1, MuchBoolean.one_zero(true)
73
+ assert_equal 0, MuchBoolean.one_zero(false)
74
+
75
+ assert_true MuchBoolean.convert(MuchBoolean.one_zero(true))
76
+ assert_false MuchBoolean.convert(MuchBoolean.one_zero(false))
77
+ end
78
+
79
+ should "encode booleans as true/false strings" do
80
+ assert_equal 'true', MuchBoolean.true_false(true)
81
+ assert_equal 'false', MuchBoolean.true_false(false)
82
+ assert_equal 'True', MuchBoolean.True_False(true)
83
+ assert_equal 'False', MuchBoolean.True_False(false)
84
+ assert_equal 'TRUE', MuchBoolean.TRUE_FALSE(true)
85
+ assert_equal 'FALSE', MuchBoolean.TRUE_FALSE(false)
86
+ assert_equal 't', MuchBoolean.t_f(true)
87
+ assert_equal 'f', MuchBoolean.t_f(false)
88
+ assert_equal 'T', MuchBoolean.T_F(true)
89
+ assert_equal 'F', MuchBoolean.T_F(false)
90
+
91
+ assert_true MuchBoolean.convert(MuchBoolean.true_false(true))
92
+ assert_false MuchBoolean.convert(MuchBoolean.true_false(false))
93
+ assert_true MuchBoolean.convert(MuchBoolean.True_False(true))
94
+ assert_false MuchBoolean.convert(MuchBoolean.True_False(false))
95
+ assert_true MuchBoolean.convert(MuchBoolean.TRUE_FALSE(true))
96
+ assert_false MuchBoolean.convert(MuchBoolean.TRUE_FALSE(false))
97
+ assert_true MuchBoolean.convert(MuchBoolean.t_f(true))
98
+ assert_false MuchBoolean.convert(MuchBoolean.t_f(false))
99
+ assert_true MuchBoolean.convert(MuchBoolean.T_F(true))
100
+ assert_false MuchBoolean.convert(MuchBoolean.T_F(false))
101
+ end
102
+
103
+ should "encode booleans as yes/no strings" do
104
+ assert_equal 'yes', MuchBoolean.yes_no(true)
105
+ assert_equal 'no', MuchBoolean.yes_no(false)
106
+ assert_equal 'Yes', MuchBoolean.Yes_No(true)
107
+ assert_equal 'No', MuchBoolean.Yes_No(false)
108
+ assert_equal 'YES', MuchBoolean.YES_NO(true)
109
+ assert_equal 'NO', MuchBoolean.YES_NO(false)
110
+ assert_equal 'y', MuchBoolean.y_n(true)
111
+ assert_equal 'n', MuchBoolean.y_n(false)
112
+ assert_equal 'Y', MuchBoolean.Y_N(true)
113
+ assert_equal 'N', MuchBoolean.Y_N(false)
114
+
115
+ assert_true MuchBoolean.convert(MuchBoolean.yes_no(true))
116
+ assert_false MuchBoolean.convert(MuchBoolean.yes_no(false))
117
+ assert_true MuchBoolean.convert(MuchBoolean.Yes_No(true))
118
+ assert_false MuchBoolean.convert(MuchBoolean.Yes_No(false))
119
+ assert_true MuchBoolean.convert(MuchBoolean.YES_NO(true))
120
+ assert_false MuchBoolean.convert(MuchBoolean.YES_NO(false))
121
+ assert_true MuchBoolean.convert(MuchBoolean.y_n(true))
122
+ assert_false MuchBoolean.convert(MuchBoolean.y_n(false))
123
+ assert_true MuchBoolean.convert(MuchBoolean.Y_N(true))
124
+ assert_false MuchBoolean.convert(MuchBoolean.Y_N(false))
125
+ end
126
+
68
127
  end
69
128
 
70
129
  class InitTests < UnitTests
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: much-boolean
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2016-01-11 00:00:00 Z
13
+ date: 2016-02-09 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: assert