string_foundation 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +9 -0
  3. data/CODE_OF_CONDUCT.md +75 -0
  4. data/Gemfile +38 -0
  5. data/Gemfile.lock +58 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +324 -0
  8. data/Rakefile +13 -0
  9. data/bin/console +15 -0
  10. data/bin/setup +11 -0
  11. data/circle.yml +14 -0
  12. data/coverage/assets/0.10.0/application.css +799 -0
  13. data/coverage/assets/0.10.0/application.js +1707 -0
  14. data/coverage/assets/0.10.0/colorbox/border.png +0 -0
  15. data/coverage/assets/0.10.0/colorbox/controls.png +0 -0
  16. data/coverage/assets/0.10.0/colorbox/loading.gif +0 -0
  17. data/coverage/assets/0.10.0/colorbox/loading_background.png +0 -0
  18. data/coverage/assets/0.10.0/favicon_green.png +0 -0
  19. data/coverage/assets/0.10.0/favicon_red.png +0 -0
  20. data/coverage/assets/0.10.0/favicon_yellow.png +0 -0
  21. data/coverage/assets/0.10.0/loading.gif +0 -0
  22. data/coverage/assets/0.10.0/magnify.png +0 -0
  23. data/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  24. data/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  25. data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  26. data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  27. data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  28. data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  29. data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  30. data/coverage/assets/0.10.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  31. data/coverage/assets/0.10.0/smoothness/images/ui-icons_222222_256x240.png +0 -0
  32. data/coverage/assets/0.10.0/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  33. data/coverage/assets/0.10.0/smoothness/images/ui-icons_454545_256x240.png +0 -0
  34. data/coverage/assets/0.10.0/smoothness/images/ui-icons_888888_256x240.png +0 -0
  35. data/coverage/assets/0.10.0/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  36. data/coverage/index.html +12508 -0
  37. data/lib/string_foundation/case.rb +102 -0
  38. data/lib/string_foundation/convert.rb +51 -0
  39. data/lib/string_foundation/convertible.rb +40 -0
  40. data/lib/string_foundation/like.rb +24 -0
  41. data/lib/string_foundation/version.rb +7 -0
  42. data/lib/string_foundation/with.rb +26 -0
  43. data/lib/string_foundation.rb +6 -0
  44. data/pkg/string_foundation-1.0.0.gem +0 -0
  45. data/spec/spec_helper.rb +40 -0
  46. data/spec/string_foundation/case_spec.rb +901 -0
  47. data/spec/string_foundation/convert_spec.rb +234 -0
  48. data/spec/string_foundation/convertaile_spec.rb +286 -0
  49. data/spec/string_foundation/like_spec.rb +218 -0
  50. data/spec/string_foundation/version_spec.rb +14 -0
  51. data/spec/string_foundation/with_spec.rb +99 -0
  52. data/spec/support/enhanced_matchers_extension.rb +11 -0
  53. data/string_foundation.gemspec +22 -0
  54. data/string_foundation.png +0 -0
  55. metadata +106 -0
@@ -0,0 +1,234 @@
1
+ # ==============================================================================
2
+ # SPEC - STRING FOUNDATION - CONVERT
3
+ # ==============================================================================
4
+ # frozen_string_literal: true
5
+ describe '[ Convert Methods ]' do
6
+
7
+ # ----------------------------------------------------------------------------
8
+ # Convert To TrueClass Or FalseClass
9
+ # ----------------------------------------------------------------------------
10
+ describe 'CONVERT TO TRUECLASS OR FALSE CLASS' do
11
+ let(:string) { nil }
12
+ subject { string.to_bool }
13
+
14
+ context 'when a string is "true",' do
15
+ let(:string) { 'true' }
16
+
17
+ it { is_expected.to eq true }
18
+ end
19
+
20
+ context 'when a string is "false",' do
21
+ let(:string) { 'false' }
22
+
23
+ it { is_expected.to eq false }
24
+ end
25
+
26
+ context 'when a string is invalid,' do
27
+ let(:string) { 'dummy' }
28
+
29
+ it { is_expected_as_block.to raise_error(TypeError) }
30
+ end
31
+ end
32
+
33
+
34
+ # ----------------------------------------------------------------------------
35
+ # Convert A BOOLY STRING To TrueClass Or FalseClass
36
+ # ----------------------------------------------------------------------------
37
+ describe 'CONVERT A BOOLY STRING TO TRUECLASS OR FALSE CLASS' do
38
+ let(:string) { nil }
39
+ subject { string.to_booly }
40
+
41
+ context 'when a string is "true",' do
42
+ let(:string) { 'true' }
43
+
44
+ it { is_expected.to eq true }
45
+ end
46
+
47
+ context 'when a string is "false",' do
48
+ let(:string) { 'false' }
49
+
50
+ it { is_expected.to eq false }
51
+ end
52
+
53
+ context 'when a string is invalid,' do
54
+ let(:string) { 'dummy' }
55
+
56
+ it { is_expected_as_block.to raise_error(TypeError) }
57
+ end
58
+
59
+ context 'when a string is a positive integral number,' do
60
+ let(:string) { '1' }
61
+
62
+ it { is_expected.to eq true }
63
+ end
64
+
65
+ context 'when a string is a negative integral number,' do
66
+ let(:string) { '-1' }
67
+
68
+ it { is_expected.to eq false }
69
+ end
70
+
71
+ context 'when a string is a positive floating point number,' do
72
+ let(:string) { '0.1' }
73
+
74
+ it { is_expected.to eq true }
75
+ end
76
+
77
+ context 'when a string is a negative floating point number,' do
78
+ let(:string) { '-0.1' }
79
+
80
+ it { is_expected.to eq false }
81
+ end
82
+
83
+ context 'when a string is 0,' do
84
+ let(:string) { '0' }
85
+
86
+ it { is_expected.to eq false }
87
+ end
88
+
89
+ context 'when a string is 0.0,' do
90
+ let(:string) { '0.0' }
91
+
92
+ it { is_expected.to eq false }
93
+ end
94
+
95
+ context 'when a string is an empty string,' do
96
+ let(:string) { '' }
97
+
98
+ it { is_expected.to eq false }
99
+ end
100
+ end
101
+
102
+
103
+ # ----------------------------------------------------------------------------
104
+ # Convert To Proper Class From String
105
+ # ----------------------------------------------------------------------------
106
+ describe 'CONVER TO PROPER CLASS FROM STRING' do
107
+ let(:string) { nil }
108
+ subject { string.to_pretty }
109
+
110
+ context 'when a string is "0",' do
111
+ let(:string) { '0' }
112
+
113
+ it { is_expected.to eq 0 }
114
+ end
115
+
116
+ context 'when a string is "1",' do
117
+ let(:string) { '1' }
118
+
119
+ it { is_expected.to eq 1 }
120
+ end
121
+
122
+ context 'when a string is "000123",' do
123
+ let(:string) { '000123' }
124
+
125
+ it { is_expected.to eq 123 }
126
+ end
127
+
128
+ context 'when a string is "0.0",' do
129
+ let(:string) { '0.0' }
130
+
131
+ it { is_expected.to eq 0.0 }
132
+ end
133
+
134
+ context 'when a string is "000.00123",' do
135
+ let(:string) { '000.00123' }
136
+
137
+ it { is_expected.to eq 0.00123 }
138
+ end
139
+
140
+ context 'when a string is "true",' do
141
+ let(:string) { 'true' }
142
+
143
+ it { is_expected.to eq true }
144
+ end
145
+
146
+ context 'when a string is "false",' do
147
+ let(:string) { 'false' }
148
+
149
+ it { is_expected.to eq false }
150
+ end
151
+
152
+ context 'when a string is "dummy",' do
153
+ let(:string) { 'dummy' }
154
+
155
+ it { is_expected.to eq string }
156
+ end
157
+
158
+ context 'when a string is an empty string,' do
159
+ let(:string) { '' }
160
+
161
+ it { is_expected.to eq nil }
162
+ end
163
+ end
164
+
165
+
166
+ # ----------------------------------------------------------------------------
167
+ # Convert From Newline To Characters
168
+ # ----------------------------------------------------------------------------
169
+ describe 'CONVERT FROM NEWLINE TO CHARACTERS' do
170
+ let(:string) { "We are Brushdown.\nWe are Brushdown." }
171
+ let(:char) { '<br>' }
172
+ subject { string.nl_to(char) }
173
+
174
+ context 'when a string has newlines "\n",' do
175
+ it { is_expected.to eq 'We are Brushdown.<br>We are Brushdown.' }
176
+ end
177
+
178
+ context 'when a string has newlines "\r\n",' do
179
+ let(:string) { "We are Brushdown.\r\nWe are Brushdown." }
180
+
181
+ it { is_expected.to eq 'We are Brushdown.<br>We are Brushdown.' }
182
+ end
183
+
184
+ context 'when a string does not have newlines,' do
185
+ let(:string) { "We are Brushdown. We are Brushdown." }
186
+
187
+ it { is_expected.to eq string }
188
+ end
189
+
190
+ context 'when an argument is not set,' do
191
+ subject { string.nl_to() }
192
+
193
+ it { is_expected_as_block.to raise_error(ArgumentError) }
194
+ end
195
+
196
+ context 'when an argument is nil,' do
197
+ let(:char) { nil }
198
+
199
+ it { is_expected.to eq 'We are Brushdown.We are Brushdown.' }
200
+ end
201
+
202
+ context 'when an argument is an empty string,' do
203
+ let(:char) { '' }
204
+
205
+ it { is_expected.to eq 'We are Brushdown.We are Brushdown.' }
206
+ end
207
+ end
208
+
209
+
210
+ # ----------------------------------------------------------------------------
211
+ # Convert From Newline To <br>
212
+ # ----------------------------------------------------------------------------
213
+ describe 'CONVERT FROM NEWLINE TO `<br>`' do
214
+ let(:string) { "We are Brushdown.\nWe are Brushdown." }
215
+ subject { string.nl_to_br }
216
+
217
+ context 'when a string has newlines "\n",' do
218
+ it { is_expected.to eq 'We are Brushdown.<br>We are Brushdown.' }
219
+ end
220
+
221
+ context 'when a string has newlines "\r\n",' do
222
+ let(:string) { "We are Brushdown.\r\nWe are Brushdown." }
223
+
224
+ it { is_expected.to eq 'We are Brushdown.<br>We are Brushdown.' }
225
+ end
226
+
227
+ context 'when a string does not have newlines,' do
228
+ let(:string) { "We are Brushdown. We are Brushdown." }
229
+
230
+ it { is_expected.to eq string }
231
+ end
232
+ end
233
+
234
+ end
@@ -0,0 +1,286 @@
1
+ # ==============================================================================
2
+ # SPEC - STRING FOUNDATION - CONVERTIBLE
3
+ # ==============================================================================
4
+ # frozen_string_literal: true
5
+ describe '[ Convertible Methods ]' do
6
+
7
+ # ----------------------------------------------------------------------------
8
+ # Check Convertible To Integer
9
+ # ----------------------------------------------------------------------------
10
+ describe 'CHECK CONVERTIBLE TO INTEGER' do
11
+ let(:string) { nil }
12
+ subject { string.to_i? }
13
+
14
+ context 'when a string is an integral number,' do
15
+ context 'and it is a positive number,' do
16
+ let(:string) { '123' }
17
+
18
+ it { is_expected.to eq true }
19
+ end
20
+
21
+ context 'and it is a positive number with a sign,' do
22
+ let(:string) { '+123' }
23
+
24
+ it { is_expected.to eq true }
25
+ end
26
+
27
+ context 'and it is a negative number,' do
28
+ let(:string) { '-5' }
29
+
30
+ it { is_expected.to eq true }
31
+ end
32
+ end
33
+
34
+ context 'when a string is a floating point number,' do
35
+ context 'and it is a positive number,' do
36
+ let(:string) { '0.123' }
37
+
38
+ it { is_expected.to eq true }
39
+ end
40
+
41
+ context 'and it is a positive number with a sign,' do
42
+ let(:string) { '+0.123' }
43
+
44
+ it { is_expected.to eq true }
45
+ end
46
+
47
+ context 'and it is a negative number,' do
48
+ let(:string) { '-5.123' }
49
+
50
+ it { is_expected.to eq true }
51
+ end
52
+ end
53
+
54
+ context 'when a string is a floating point number without an integer,' do
55
+ context 'and it is a positive number,' do
56
+ let(:string) { '.123' }
57
+
58
+ it { is_expected.to eq true }
59
+ end
60
+
61
+ context 'and it is a positive number with a sign,' do
62
+ let(:string) { '+.123' }
63
+
64
+ it { is_expected.to eq true }
65
+ end
66
+
67
+ context 'and it is a negative number,' do
68
+ let(:string) { '-.123' }
69
+
70
+ it { is_expected.to eq true }
71
+ end
72
+ end
73
+
74
+ context 'when a string a number has leading zeros,' do
75
+ context 'and it is a positive number,' do
76
+ let(:string) { '00000123' }
77
+
78
+ it { is_expected.to eq true }
79
+ end
80
+
81
+ context 'and it is a positive number with a sign,' do
82
+ let(:string) { '+00000123' }
83
+
84
+ it { is_expected.to eq true }
85
+ end
86
+
87
+ context 'and it is a negative number,' do
88
+ let(:string) { '-00000123' }
89
+
90
+ it { is_expected.to eq true }
91
+ end
92
+ end
93
+
94
+ context 'when a string is not a number,' do
95
+ let(:string) { 'abc' }
96
+
97
+ it { is_expected.to eq false }
98
+ end
99
+ end
100
+
101
+
102
+ # ----------------------------------------------------------------------------
103
+ # Check Convertible To Float
104
+ # ----------------------------------------------------------------------------
105
+ describe 'CHECK CONVERTIBLE TO FLOAT' do
106
+ let(:string) { nil }
107
+ subject { string.to_f? }
108
+
109
+ context 'when a string is an integral number,' do
110
+ context 'and it is a positive number,' do
111
+ let(:string) { '123' }
112
+
113
+ it { is_expected.to eq true }
114
+ end
115
+
116
+ context 'and it is a positive number with a sign,' do
117
+ let(:string) { '+123' }
118
+
119
+ it { is_expected.to eq true }
120
+ end
121
+
122
+ context 'and it is a negative number,' do
123
+ let(:string) { '-5' }
124
+
125
+ it { is_expected.to eq true }
126
+ end
127
+ end
128
+
129
+ context 'when a string is a floating point number,' do
130
+ context 'and it is a positive number,' do
131
+ let(:string) { '0.123' }
132
+
133
+ it { is_expected.to eq true }
134
+ end
135
+
136
+ context 'and it is a positive number with a sign,' do
137
+ let(:string) { '+0.123' }
138
+
139
+ it { is_expected.to eq true }
140
+ end
141
+
142
+ context 'and it is a negative number,' do
143
+ let(:string) { '-5.123' }
144
+
145
+ it { is_expected.to eq true }
146
+ end
147
+ end
148
+
149
+ context 'when a string is a floating point number without an integer,' do
150
+ context 'and it is a positive number,' do
151
+ let(:string) { '.123' }
152
+
153
+ it { is_expected.to eq true }
154
+ end
155
+
156
+ context 'and it is a positive number with a sign,' do
157
+ let(:string) { '+.123' }
158
+
159
+ it { is_expected.to eq true }
160
+ end
161
+
162
+ context 'and it is a negative number,' do
163
+ let(:string) { '-.123' }
164
+
165
+ it { is_expected.to eq true }
166
+ end
167
+ end
168
+
169
+ context 'when a string a number has leading zeros,' do
170
+ context 'and it is a positive number,' do
171
+ let(:string) { '00000123' }
172
+
173
+ it { is_expected.to eq true }
174
+ end
175
+
176
+ context 'and it is a positive number with a sign,' do
177
+ let(:string) { '+00000123' }
178
+
179
+ it { is_expected.to eq true }
180
+ end
181
+
182
+ context 'and it is a negative number,' do
183
+ let(:string) { '-00000123' }
184
+
185
+ it { is_expected.to eq true }
186
+ end
187
+ end
188
+
189
+ context 'when a string is not a number,' do
190
+ let(:string) { 'abc' }
191
+
192
+ it { is_expected.to eq false }
193
+ end
194
+ end
195
+
196
+
197
+ # ----------------------------------------------------------------------------
198
+ # Check Convertible To Boolean
199
+ # ----------------------------------------------------------------------------
200
+ describe 'CHECK CONVERTIBLE TO BOOLEAN' do
201
+ let(:string) { nil }
202
+ subject { string.to_bool? }
203
+
204
+ context 'when a string is "true",' do
205
+ let(:string) { 'true' }
206
+
207
+ it { is_expected.to eq true }
208
+ end
209
+
210
+ context 'when a string is "false",' do
211
+ let(:string) { 'false' }
212
+
213
+ it { is_expected.to eq true }
214
+ end
215
+
216
+ context 'when a string is an empty,' do
217
+ let(:string) { '' }
218
+
219
+ it { is_expected.to eq false }
220
+ end
221
+
222
+ context 'when a string is a positive number,' do
223
+ let(:string) { '1' }
224
+
225
+ it { is_expected.to eq false }
226
+ end
227
+
228
+ context 'when a string is a negative number,' do
229
+ let(:string) { '-1' }
230
+
231
+ it { is_expected.to eq false }
232
+ end
233
+
234
+ context 'when a string is not a number,' do
235
+ let(:string) { 'abc' }
236
+
237
+ it { is_expected.to eq false }
238
+ end
239
+ end
240
+
241
+
242
+ # ----------------------------------------------------------------------------
243
+ # Check Convertaile To Booly
244
+ # ----------------------------------------------------------------------------
245
+ describe 'CHECK CONVERTIBLE TO BOOLYs' do
246
+ let(:string) { nil }
247
+ subject { string.to_booly? }
248
+
249
+ context 'when a string is "true",' do
250
+ let(:string) { 'true' }
251
+
252
+ it { is_expected.to eq true }
253
+ end
254
+
255
+ context 'when a string is "false",' do
256
+ let(:string) { 'false' }
257
+
258
+ it { is_expected.to eq true }
259
+ end
260
+
261
+ context 'when a string is an empty,' do
262
+ let(:string) { '' }
263
+
264
+ it { is_expected.to eq true }
265
+ end
266
+
267
+ context 'when a string is a positive number,' do
268
+ let(:string) { '1' }
269
+
270
+ it { is_expected.to eq true }
271
+ end
272
+
273
+ context 'when a string is a negative number,' do
274
+ let(:string) { '-1' }
275
+
276
+ it { is_expected.to eq true }
277
+ end
278
+
279
+ context 'when a string is not a number,' do
280
+ let(:string) { 'abc' }
281
+
282
+ it { is_expected.to eq false }
283
+ end
284
+ end
285
+
286
+ end