string_foundation 1.0.0 → 1.1.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile +9 -9
- data/Gemfile.lock +19 -19
- data/{LICENSE.txt → LICENSE} +1 -1
- data/PULL_REQUEST_TEMPLATE.md +14 -0
- data/README.md +244 -104
- data/Rakefile +3 -3
- data/bin/console +1 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/application.css +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/application.js +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/colorbox/border.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/colorbox/controls.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/colorbox/loading.gif +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/colorbox/loading_background.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/favicon_green.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/favicon_red.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/favicon_yellow.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/loading.gif +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/magnify.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/coverage/assets/{0.10.0 → 0.10.2}/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/coverage/index.html +5885 -3160
- data/lib/string_foundation.rb +4 -2
- data/lib/string_foundation/blank.rb +17 -0
- data/lib/string_foundation/case.rb +28 -38
- data/lib/string_foundation/convert.rb +9 -9
- data/lib/string_foundation/convertible.rb +4 -4
- data/lib/string_foundation/is.rb +13 -0
- data/lib/string_foundation/length.rb +56 -0
- data/lib/string_foundation/like.rb +4 -4
- data/lib/string_foundation/version.rb +2 -2
- data/lib/string_foundation/with.rb +7 -7
- data/pkg/string_foundation-1.1.0.gem +0 -0
- data/spec/spec_helper.rb +10 -10
- data/spec/string_foundation/blank_spec.rb +91 -0
- data/spec/string_foundation/case_spec.rb +398 -433
- data/spec/string_foundation/convert_spec.rb +98 -98
- data/spec/string_foundation/convertible_spec.rb +286 -0
- data/spec/string_foundation/is_spec.rb +62 -0
- data/spec/string_foundation/length_spec.rb +226 -0
- data/spec/string_foundation/like_spec.rb +103 -103
- data/spec/string_foundation/version_spec.rb +4 -4
- data/spec/string_foundation/with_spec.rb +48 -48
- data/spec/support/enhanced_matchers_extension.rb +1 -0
- data/string_foundation.gemspec +15 -14
- metadata +46 -37
- data/circle.yml +0 -14
- data/pkg/string_foundation-1.0.0.gem +0 -0
- data/spec/string_foundation/convertaile_spec.rb +0 -286
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3832f5782195390b3ea596e3b22038182cc01148
|
4
|
+
data.tar.gz: 30fde3c3f84156b30a1e7e2ba553755fbf58e206
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c635d349867d6aba69ebab82cd163d644fd5bdc27391cb453aa7f825400164bc4dcbe35aaa278e2041501422ed050f86c09e7df80370dfa08a9e432929a0f37f
|
7
|
+
data.tar.gz: 760e85994bf3d8b65882ed10d6a8e8da10ef70fc2f85e64edc07cefb4982bdc7e0d1362534ae6e304333747b4e06354ff2c29cd922007934bffd7f9bb3cf9a4e
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
<!-- CHANGELOG -->
|
3
3
|
<!-- ======================================================================= -->
|
4
4
|
# Changelog
|
5
|
+
## 1.1.0 (2018-05-28)
|
6
|
+
- Add methods to compare characters length ([#31](https://github.com/jagaapple/string_foundation.rb/pull/31)) ([#32](https://github.com/jagaapple/string_foundation.rb/pull/32)) - [@akaryu0206](https://github.com/akaryu0206)
|
7
|
+
- Add methods to check whether or not a string is empty ([#37](https://github.com/jagaapple/string_foundation.rb/pull/37)) - [@akaryu0206](https://github.com/akaryu0206)
|
8
|
+
- Add a method to compare symbol ([#38](https://github.com/jagaapple/string_foundation.rb/pull/38)) - [@akaryu0206](https://github.com/akaryu0206)
|
9
|
+
|
5
10
|
## 1.0.0 (2017-05-09)
|
6
11
|
- Initial public release - [@jagaapple](https://github.com/jagaapple), [@cosmicphi](https://github.com/cosmicphi)
|
7
12
|
|
data/Gemfile
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# ==============================================================================
|
2
2
|
# GEM FILE
|
3
|
-
# ==============================================================================
|
4
3
|
# frozen_string_literal: true
|
5
|
-
|
4
|
+
# ==============================================================================
|
5
|
+
source "https://rubygems.org"
|
6
6
|
|
7
7
|
# Specify your gem's dependencies in string_foundation.gemspec.
|
8
8
|
gemspec
|
@@ -13,8 +13,8 @@ gemspec
|
|
13
13
|
group :development, :test do
|
14
14
|
|
15
15
|
# Install bundler and rake.
|
16
|
-
gem
|
17
|
-
gem
|
16
|
+
gem "bundler"
|
17
|
+
gem "rake"
|
18
18
|
|
19
19
|
end
|
20
20
|
|
@@ -25,14 +25,14 @@ end
|
|
25
25
|
group :test do
|
26
26
|
|
27
27
|
# Use RSpec for unit test.
|
28
|
-
gem
|
28
|
+
gem "rspec"
|
29
29
|
# Use a code coverage analysis tool for Ruby.
|
30
|
-
gem
|
30
|
+
gem "simplecov"
|
31
31
|
# Output the result of SimpleCov to a console.
|
32
|
-
gem
|
32
|
+
gem "simplecov-console"
|
33
33
|
# Use Codecov to get status badges.
|
34
|
-
gem
|
34
|
+
gem "codecov"
|
35
35
|
# Generate random text.
|
36
|
-
gem
|
36
|
+
gem "random_token"
|
37
37
|
|
38
38
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
string_foundation (1.
|
4
|
+
string_foundation (1.1.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -11,34 +11,34 @@ GEM
|
|
11
11
|
json
|
12
12
|
simplecov
|
13
13
|
url
|
14
|
-
diff-lcs (1.
|
14
|
+
diff-lcs (1.3)
|
15
15
|
docile (1.1.5)
|
16
16
|
hirb (0.7.3)
|
17
|
-
json (2.0
|
18
|
-
rake (12.
|
17
|
+
json (2.1.0)
|
18
|
+
rake (12.3.0)
|
19
19
|
random_token (1.1.1)
|
20
|
-
rspec (3.
|
21
|
-
rspec-core (~> 3.
|
22
|
-
rspec-expectations (~> 3.
|
23
|
-
rspec-mocks (~> 3.
|
24
|
-
rspec-core (3.
|
25
|
-
rspec-support (~> 3.
|
26
|
-
rspec-expectations (3.
|
20
|
+
rspec (3.7.0)
|
21
|
+
rspec-core (~> 3.7.0)
|
22
|
+
rspec-expectations (~> 3.7.0)
|
23
|
+
rspec-mocks (~> 3.7.0)
|
24
|
+
rspec-core (3.7.0)
|
25
|
+
rspec-support (~> 3.7.0)
|
26
|
+
rspec-expectations (3.7.0)
|
27
27
|
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
-
rspec-support (~> 3.
|
29
|
-
rspec-mocks (3.
|
28
|
+
rspec-support (~> 3.7.0)
|
29
|
+
rspec-mocks (3.7.0)
|
30
30
|
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
-
rspec-support (~> 3.
|
32
|
-
rspec-support (3.
|
33
|
-
simplecov (0.
|
31
|
+
rspec-support (~> 3.7.0)
|
32
|
+
rspec-support (3.7.0)
|
33
|
+
simplecov (0.15.1)
|
34
34
|
docile (~> 1.1.0)
|
35
35
|
json (>= 1.8, < 3)
|
36
36
|
simplecov-html (~> 0.10.0)
|
37
|
-
simplecov-console (0.4.
|
37
|
+
simplecov-console (0.4.2)
|
38
38
|
ansi
|
39
39
|
hirb
|
40
40
|
simplecov
|
41
|
-
simplecov-html (0.10.
|
41
|
+
simplecov-html (0.10.2)
|
42
42
|
url (0.3.2)
|
43
43
|
|
44
44
|
PLATFORMS
|
@@ -55,4 +55,4 @@ DEPENDENCIES
|
|
55
55
|
string_foundation!
|
56
56
|
|
57
57
|
BUNDLED WITH
|
58
|
-
1.
|
58
|
+
1.16.0
|
data/{LICENSE.txt → LICENSE}
RENAMED
data/README.md
CHANGED
@@ -5,10 +5,10 @@
|
|
5
5
|
|
6
6
|
---
|
7
7
|
|
8
|
-
[](https://circleci.com/gh/jagaapple/string_foundation.rb)
|
9
|
+
[](https://codecov.io/gh/jagaapple/string_foundation.rb)
|
10
10
|
[](https://rubygems.org/gems/string_foundation/)
|
11
|
-
[](https://opensource.org/licenses/MIT)
|
12
12
|
[](https://twitter.com/jagaapple)
|
13
13
|
|
14
14
|
String Foundation is a Ruby library that provides useful methods for the Ruby
|
@@ -17,18 +17,30 @@ string class.
|
|
17
17
|
|
18
18
|
## Table of Contents
|
19
19
|
|
20
|
-
<!--
|
20
|
+
<!-- TOC depthFrom:2 -->
|
21
21
|
|
22
|
+
- [Table of Contents](#table-of-contents)
|
22
23
|
- [Quick Start](#quick-start)
|
23
24
|
- [Requirements](#requirements)
|
24
25
|
- [Installation](#installation)
|
25
26
|
- [Basic Usage](#basic-usage)
|
27
|
+
- [The Blank Methods](#the-blank-methods)
|
28
|
+
- [Check To Blank](#check-to-blank)
|
29
|
+
- [Check To Present](#check-to-present)
|
30
|
+
- [The Is Methods](#the-is-methods)
|
31
|
+
- [Is Symbol](#is-symbol)
|
32
|
+
- [The Length Methods](#the-length-methods)
|
33
|
+
- [Equal To](#equal-to)
|
34
|
+
- [Less Than](#less-than)
|
35
|
+
- [Less Than Or Equal To](#less-than-or-equal-to)
|
36
|
+
- [Greater Than](#greater-than)
|
37
|
+
- [Greater Than Or Equal To](#greater-than-or-equal-to)
|
26
38
|
- [The Convertible Methods](#the-convertible-methods)
|
27
39
|
- [To Integer](#to-integer)
|
28
40
|
- [To Float](#to-float)
|
29
41
|
- [To TrueClass / FalseClass](#to-trueclass--falseclass)
|
30
42
|
- [The With Methods](#the-with-methods)
|
31
|
-
- [Remove Leading Zeros
|
43
|
+
- [Remove Leading Zeros (Zero Padding)](#remove-leading-zeros-zero-padding)
|
32
44
|
- [The Convert Methods](#the-convert-methods)
|
33
45
|
- [To TrueClass / FalseClass](#to-trueclass--falseclass-1)
|
34
46
|
- [To Proper Class](#to-proper-class)
|
@@ -40,7 +52,7 @@ string class.
|
|
40
52
|
- [Contributing to String Foundation](#contributing-to-string-foundation)
|
41
53
|
- [License](#license)
|
42
54
|
|
43
|
-
<!-- /
|
55
|
+
<!-- /TOC -->
|
44
56
|
|
45
57
|
|
46
58
|
## Quick Start
|
@@ -58,7 +70,7 @@ $ gem install string_foundation
|
|
58
70
|
If you are using Bundler, add this line to your application's Gemfile:
|
59
71
|
|
60
72
|
```ruby
|
61
|
-
gem
|
73
|
+
gem "string_foundation"
|
62
74
|
```
|
63
75
|
|
64
76
|
And then run `bundle install` .
|
@@ -67,19 +79,148 @@ And then run `bundle install` .
|
|
67
79
|
The following is a sample of what String Foundation provides.
|
68
80
|
|
69
81
|
```ruby
|
82
|
+
# Check characters length.
|
83
|
+
"abc".length?(3) #=> true
|
84
|
+
"password".length?(8..32) #=> true
|
85
|
+
"password".gte?(8) #=> true
|
86
|
+
"password".lte?(32) #=> true
|
87
|
+
|
88
|
+
# Compare a symbol.
|
89
|
+
"abc".is_sym?(:abc) #=> true
|
90
|
+
|
70
91
|
# Check for convertible.
|
71
|
-
|
72
|
-
|
92
|
+
"123".to_i? #=> true
|
93
|
+
"x123".to_i? #=> false
|
73
94
|
|
74
95
|
# Remove leading zeros.
|
75
|
-
|
96
|
+
"00000123".without_leading_zeros #=> "123"
|
76
97
|
|
77
98
|
# Convert a value to the appropriate type.
|
78
|
-
|
79
|
-
|
99
|
+
"false".to_pretty #=> false
|
100
|
+
".5".to_pretty #=> 0.5
|
80
101
|
|
81
102
|
# Convert to lowerCamelCase.
|
82
|
-
|
103
|
+
"user_id".to_lcamel #=> "userId"
|
104
|
+
```
|
105
|
+
|
106
|
+
|
107
|
+
## The Blank Methods
|
108
|
+
The Blank Methods enable you to check whether or not a string is empty. These
|
109
|
+
methods return `true` or `false` .
|
110
|
+
|
111
|
+
### Check To Blank
|
112
|
+
The `blank?` method checks whether a string is blank (it is an empty string or
|
113
|
+
includes only half-width spaces or newlines). If a string is blank, return `true` ,
|
114
|
+
unless return `false` .
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
"".blank? #=> true
|
118
|
+
" ".blank? #=> true
|
119
|
+
" ".blank? #=> true
|
120
|
+
" \n ".blank? #=> true
|
121
|
+
|
122
|
+
"abc".blank? #=> false
|
123
|
+
```
|
124
|
+
|
125
|
+
### Check To Present
|
126
|
+
The `present?` method checks whether a string is present (it is not an empty string
|
127
|
+
or does not include only half-width spaces or newlines). If a string is present,
|
128
|
+
return `true` , unless return `false` .
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
"".present? #=> false
|
132
|
+
" ".present? #=> false
|
133
|
+
" ".present? #=> false
|
134
|
+
" \n ".present? #=> false
|
135
|
+
|
136
|
+
"abc".present? #=> true
|
137
|
+
```
|
138
|
+
|
139
|
+
|
140
|
+
## The Is Methods
|
141
|
+
The Is Methods enable you to check whether or not a string is nearly equal to
|
142
|
+
a specific value. These methods return `true` or `false` .
|
143
|
+
|
144
|
+
### Is Symbol
|
145
|
+
The `is_sym?` method checks whether a string is nearly equal to a specific Symbol.
|
146
|
+
This returns `true` only if it is, unless return `false` . This method accepts
|
147
|
+
only Symbol.
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
"abc".is_sym?(:abc) #=> true
|
151
|
+
"".is_sym?(:"") #=> true
|
152
|
+
"abc".is_sym?(:def) #=> false
|
153
|
+
|
154
|
+
"abc".is_sym?("abc") #=> ArgumentError
|
155
|
+
```
|
156
|
+
|
157
|
+
|
158
|
+
## The Length Methods
|
159
|
+
The Length methods enable you to check whether or not characters length is a
|
160
|
+
specific length. These methods return `true` or `false` .
|
161
|
+
|
162
|
+
### Equal To
|
163
|
+
The `length?` method checks whether characters length is equal to a specific
|
164
|
+
length. If its case, return `true` , unless return `false` .
|
165
|
+
This method accepts number of Integer (including Fixnum and Bignum classes).
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
"abc".length?(3) #=> true
|
169
|
+
"abc".length?(4) #=> false
|
170
|
+
|
171
|
+
"abc".length?("3") #=> ArgumentError
|
172
|
+
```
|
173
|
+
|
174
|
+
Also this method accepts Range. In that case, characters length is within a range,
|
175
|
+
return `true` , unless return `false` .
|
176
|
+
|
177
|
+
```ruby
|
178
|
+
"abc".length?(2..5) #=> true
|
179
|
+
"abc".length?(8..32) #=> false
|
180
|
+
```
|
181
|
+
|
182
|
+
### Less Than
|
183
|
+
The `length_lt?` method checks whether characters length is less than a specific
|
184
|
+
length. If its case, return `true` , unless return `false` .
|
185
|
+
This method accepts only number of Integer (including Fixnum and Bignum classes).
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
"abc".length_lt?(2) #=> false
|
189
|
+
"abc".length_lt?(3) #=> false
|
190
|
+
"abc".length_lt?(4) #=> true
|
191
|
+
```
|
192
|
+
|
193
|
+
### Less Than Or Equal To
|
194
|
+
The `length_lte?` method checks whether characters length is less than or equal
|
195
|
+
to a specific length. If its case, return `true` , unless return `false` .
|
196
|
+
This method accepts only number of Integer (including Fixnum and Bignum classes).
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
"abc".length_lte?(2) #=> false
|
200
|
+
"abc".length_lte?(3) #=> true
|
201
|
+
"abc".length_lte?(4) #=> true
|
202
|
+
```
|
203
|
+
|
204
|
+
### Greater Than
|
205
|
+
The `length_gt?` method checks whether characters length is greater than a specific
|
206
|
+
length. If its case, return `true` , unless return `false` .
|
207
|
+
This method accepts only number of Integer (including Fixnum and Bignum classes).
|
208
|
+
|
209
|
+
```ruby
|
210
|
+
"abc".length_gt?(2) #=> true
|
211
|
+
"abc".length_gt?(3) #=> false
|
212
|
+
"abc".length_gt?(4) #=> false
|
213
|
+
```
|
214
|
+
|
215
|
+
### Greater Than Or Equal To
|
216
|
+
The `length_gte?` method checks whether characters length is greater than or equal
|
217
|
+
to a specific length. If its case, return `true` , unless return `false` .
|
218
|
+
This method accepts only number of Integer (including Fixnum and Bignum classes).
|
219
|
+
|
220
|
+
```ruby
|
221
|
+
"abc".length_gte?(2) #=> true
|
222
|
+
"abc".length_gte?(3) #=> true
|
223
|
+
"abc".length_gte?(4) #=> false
|
83
224
|
```
|
84
225
|
|
85
226
|
|
@@ -93,21 +234,21 @@ The `to_i?` method checks whether a string can be converted to an Integer
|
|
93
234
|
is convertible, therefore it is not required for the argument to be an integral
|
94
235
|
number. If you pass a floating point number as an argument to this method, it will
|
95
236
|
return `true` because it can be converted using the `to_i` Ruby built-in method
|
96
|
-
(for example, `
|
237
|
+
(for example, `"0.4".to_i` returns `0` ).
|
97
238
|
|
98
239
|
```ruby
|
99
|
-
|
100
|
-
|
101
|
-
|
240
|
+
"123".to_i? #=> true
|
241
|
+
"0.3".to_i? #=> true
|
242
|
+
".2".to_i? #=> true
|
102
243
|
|
103
|
-
|
104
|
-
|
244
|
+
"abc".to_i? #=> false
|
245
|
+
"2x".to_i? #=> false
|
105
246
|
```
|
106
247
|
|
107
248
|
If an argument has leading zeros, they will be removed before checking.
|
108
249
|
|
109
250
|
```ruby
|
110
|
-
|
251
|
+
"00000123".to_i? #=> true
|
111
252
|
```
|
112
253
|
|
113
254
|
### To Float
|
@@ -115,42 +256,41 @@ The `to_f?` method is to check convertibility to the Float class. This returns
|
|
115
256
|
`true` only when an argument is convertible, therefore it is not required for the
|
116
257
|
argument to be a floating point number. If you pass an integral number as an
|
117
258
|
argument to this method, it will return `true` because it can be converted using
|
118
|
-
the `to_f` Ruby built-in method (for example, `
|
259
|
+
the `to_f` Ruby built-in method (for example, `"2".to_f` returns `2.0` ).
|
119
260
|
|
120
261
|
```ruby
|
121
|
-
|
122
|
-
|
123
|
-
|
262
|
+
"0.3".to_f? #=> true
|
263
|
+
"2".to_f? #=> true
|
264
|
+
".2".to_f? #=> true
|
124
265
|
|
125
|
-
|
126
|
-
|
266
|
+
"abc".to_f? #=> false
|
267
|
+
"2.0x".to_f? #=> false
|
127
268
|
```
|
128
269
|
|
129
|
-
|
130
270
|
### To TrueClass / FalseClass
|
131
271
|
The `to_bool?` method checks whether a string is convertible to TrueClass or
|
132
|
-
FalseClass. This returns `true` or `false` only when the string is `
|
133
|
-
`
|
272
|
+
FalseClass. This returns `true` or `false` only when the string is `"true"` or
|
273
|
+
`"false"` .
|
134
274
|
|
135
275
|
```ruby
|
136
|
-
|
137
|
-
|
276
|
+
"true".to_bool? #=> true
|
277
|
+
"false".to_bool? #=> true
|
138
278
|
|
139
|
-
|
140
|
-
|
279
|
+
"abc".to_bool? #=> false
|
280
|
+
"123".to_bool? #=> false
|
141
281
|
```
|
142
282
|
|
143
283
|
String Foundation also provides a check for a string's convertibility to a "Booly"
|
144
284
|
(truthy or falsy). This returns `true` only when the string is a positive number,
|
145
|
-
`
|
285
|
+
`"true"` , or an empty string. If not, it returns `false` .
|
146
286
|
|
147
287
|
```ruby
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
288
|
+
"true".to_booly? #=> true
|
289
|
+
"123".to_booly? #=> true
|
290
|
+
"".to_booly? #=> true
|
291
|
+
"-3".to_booly? #=> true
|
152
292
|
|
153
|
-
|
293
|
+
"abc".to_booly? #=> false
|
154
294
|
```
|
155
295
|
|
156
296
|
|
@@ -163,10 +303,10 @@ The `without_leading_zeros` method removes leading zeros (called "zero padding")
|
|
163
303
|
This supports a floating point number and a string starting with a plus or minus sign.
|
164
304
|
|
165
305
|
```ruby
|
166
|
-
|
167
|
-
|
306
|
+
"00001".without_leading_zeros #=> "1"
|
307
|
+
"-0000.3".without_leading_zeros #=> "-0.3"
|
168
308
|
|
169
|
-
|
309
|
+
["00001", "00003", "00008"].map { |num| num.without_leading_zeros } #=> ["1", "3", "8"]
|
170
310
|
```
|
171
311
|
|
172
312
|
|
@@ -178,53 +318,53 @@ or a proper class object. The Convert Methods make it easy to convert to these
|
|
178
318
|
excluded classes.
|
179
319
|
|
180
320
|
### To TrueClass / FalseClass
|
181
|
-
The `to_bool` method is for converting from a `
|
321
|
+
The `to_bool` method is for converting from a `"true"` or `"false"` string to `true`
|
182
322
|
or `false` , otherwise it will raise a `TypeError` .
|
183
323
|
|
184
324
|
```ruby
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
325
|
+
"true".to_bool #=> true
|
326
|
+
"false".to_bool #=> false
|
327
|
+
|
328
|
+
"1".to_bool #=> TypeError
|
329
|
+
"0".to_bool #=> TypeError
|
330
|
+
"-1".to_bool #=> TypeError
|
331
|
+
"abc".to_bool #=> TypeError
|
332
|
+
"".to_bool #=> TypeError
|
193
333
|
```
|
194
334
|
|
195
335
|
If you want to convert a Booly string, you can use the `to_booly` method. When a
|
196
|
-
string is `
|
336
|
+
string is `"true"` or a positive number, this method will return `true` . Otherwise
|
197
337
|
it will return `false` .
|
198
338
|
|
199
339
|
```ruby
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
340
|
+
"true".to_booly #=> true
|
341
|
+
"false".to_booly #=> false
|
342
|
+
|
343
|
+
"1".to_booly #=> true
|
344
|
+
"0".to_booly #=> false
|
345
|
+
"-1".to_booly #=> false
|
346
|
+
"abc".to_booly #=> TypeError
|
347
|
+
"".to_booly #=> false
|
208
348
|
```
|
209
349
|
|
210
350
|
### To Proper Class
|
211
351
|
The `to_pretty` method is powerful. This method can convert to a proper class,
|
212
|
-
for example, it will return a TrueClass `true` when a string is `
|
213
|
-
an Integer `1` when a string is `
|
352
|
+
for example, it will return a TrueClass `true` when a string is `"true"`, or returns
|
353
|
+
an Integer `1` when a string is `"1"`.
|
214
354
|
Also this returns `nil` when a string is an empty string.
|
215
355
|
|
216
356
|
```ruby
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
357
|
+
"1".to_pretty #=> 1
|
358
|
+
"-3".to_pretty #=> -3
|
359
|
+
"0004".to_pretty #=> 4
|
360
|
+
"0.1".to_pretty #=> 0.1
|
361
|
+
"-.5".to_pretty #=> -0.5
|
362
|
+
"00.01".to_pretty #=> 0.01
|
223
363
|
|
224
|
-
|
225
|
-
|
364
|
+
"true".to_pretty #=> true
|
365
|
+
"false".to_pretty #=> false
|
226
366
|
|
227
|
-
|
367
|
+
"".to_pretty #=> nil
|
228
368
|
```
|
229
369
|
|
230
370
|
### Newlines To Characters
|
@@ -232,8 +372,8 @@ The `nl_to` method converts a string with newlines to its specific characters.
|
|
232
372
|
The `nl2` method is an alias for `nl_to` .
|
233
373
|
|
234
374
|
```ruby
|
235
|
-
"Hi!\
|
236
|
-
"Hi!\
|
375
|
+
"Hi!\nI am Jaga Apple.".nl_to(" / ") #=> "Hi! / I am Jaga Apple."
|
376
|
+
"Hi!\nI am Jaga Apple.".nl2(" / ") #=> "Hi! / I am Jaga Apple."
|
237
377
|
```
|
238
378
|
|
239
379
|
The `nl_to_br` method replaces the newlines in a string with HTML tag `<br>` for
|
@@ -241,14 +381,14 @@ break line.
|
|
241
381
|
The `nl2br` method is an alias for `nl_to_br` .
|
242
382
|
|
243
383
|
```ruby
|
244
|
-
"Hi!\
|
245
|
-
"Hi!\
|
384
|
+
"Hi!\nI am Jaga Apple.".nl_to_br #=> "Hi!<br>I am Jaga Apple."
|
385
|
+
"Hi!\nI am Jaga Apple.".nl2br #=> "Hi!<br>I am Jaga Apple."
|
246
386
|
```
|
247
387
|
|
248
388
|
|
249
389
|
## The Like Methods
|
250
390
|
The Like Methods provide to check whether a string is an integral number or a
|
251
|
-
floating point number. These method ignore leading zeros, so the string `
|
391
|
+
floating point number. These method ignore leading zeros, so the string `"000123"`
|
252
392
|
is regarded as an integral number. These method return `true` or `false` .
|
253
393
|
|
254
394
|
The Like Methods check whether a string is an integral number or a floating point
|
@@ -259,26 +399,26 @@ as an integral number. These methods return `true` or `false` .
|
|
259
399
|
The `like_i?` method checks whether a string is an integral number.
|
260
400
|
|
261
401
|
```ruby
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
402
|
+
"123".like_i? #=> true
|
403
|
+
"00123".like_i? #=> true
|
404
|
+
"0.3".like_i? #=> false
|
405
|
+
".2".like_i? #=> false
|
266
406
|
|
267
|
-
|
268
|
-
|
407
|
+
"abc".like_i? #=> false
|
408
|
+
"2x".like_i? #=> false
|
269
409
|
```
|
270
410
|
|
271
411
|
### Like Float
|
272
412
|
The `like_f?` method checks whether a string is a floating point number.
|
273
413
|
|
274
414
|
```ruby
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
415
|
+
"123".like_f? #=> false
|
416
|
+
"00123".like_f? #=> false
|
417
|
+
"0.3".like_f? #=> true
|
418
|
+
".2".like_f? #=> true
|
279
419
|
|
280
|
-
|
281
|
-
|
420
|
+
"abc".like_f? #=> false
|
421
|
+
"2x".like_f? #=> false
|
282
422
|
```
|
283
423
|
|
284
424
|
|
@@ -286,28 +426,28 @@ The `like_f?` method checks whether a string is a floating point number.
|
|
286
426
|
The Case Methods convert to a case style, such as `lowerCamelCase` and
|
287
427
|
`lower_snake_case` . The following methods are available.
|
288
428
|
|
289
|
-
| METHOD NAME | CASE STYLE | EXAMPLE
|
290
|
-
|
291
|
-
| `to_lcamel` | Lower Camel Case | `
|
292
|
-
| `to_ucamel` | Upper Camel Case | `
|
293
|
-
| `to_lsnake` | Lower Snake Case | `
|
294
|
-
| `to_usnake` | Upper Snake Case
|
295
|
-
| `to_lkebab` | Lower Kebab Case (Chain Case) | `
|
296
|
-
| `to_ukebab` | Upper Kebab Case (Train Case) | `
|
297
|
-
| `to_lspace` | Lower Space Case (Lower Case) | `
|
298
|
-
| `to_uspace` | Upper Space Case (Start Case) | `
|
299
|
-
| `to_ldot` | Lower Dot Case | `
|
300
|
-
| `to_udot` | Upper Dot Case | `
|
429
|
+
| METHOD NAME | CASE STYLE | EXAMPLE |
|
430
|
+
|:------------|:------------------------------|:------------------|
|
431
|
+
| `to_lcamel` | Lower Camel Case | `iAmJagaApple` |
|
432
|
+
| `to_ucamel` | Upper Camel Case | `IAmJagaApple` |
|
433
|
+
| `to_lsnake` | Lower Snake Case | `i_am_jaga_apple` |
|
434
|
+
| `to_usnake` | Upper Snake Case | `I_Am_Jaga_Apple` |
|
435
|
+
| `to_lkebab` | Lower Kebab Case (Chain Case) | `i-am-jaga-apple` |
|
436
|
+
| `to_ukebab` | Upper Kebab Case (Train Case) | `I-Am-Jaga-Apple` |
|
437
|
+
| `to_lspace` | Lower Space Case (Lower Case) | `i am jaga apple` |
|
438
|
+
| `to_uspace` | Upper Space Case (Start Case) | `I Am Jaga Apple` |
|
439
|
+
| `to_ldot` | Lower Dot Case | `i.am.jaga.apple` |
|
440
|
+
| `to_udot` | Upper Dot Case | `I.Am.Jaga.Apple` |
|
301
441
|
|
302
442
|
```ruby
|
303
|
-
|
304
|
-
|
443
|
+
"user_id".to_lcamel #=> "userId"
|
444
|
+
"createdAt".to_lsnake #=> "created_at"
|
305
445
|
```
|
306
446
|
|
307
447
|
|
308
448
|
## Contributing to String Foundation
|
309
449
|
Bug reports and pull requests are welcome on GitHub at
|
310
|
-
[https://github.com/
|
450
|
+
[https://github.com/jagaapple/string_foundation.rb](https://github.com/jagaapple/string_foundation.rb).
|
311
451
|
This project is intended to be a safe, welcoming space for collaboration, and
|
312
452
|
contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org)
|
313
453
|
code of conduct.
|
@@ -321,4 +461,4 @@ For more details, see [GitHub Flow – Scott Chacon](http://scottchacon.com/2011
|
|
321
461
|
## License
|
322
462
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
323
463
|
|
324
|
-
Copyright 2017 Jaga Apple
|
464
|
+
Copyright 2017 Jaga Apple. All rights reserved.
|