string_foundation 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +9 -0
- data/CODE_OF_CONDUCT.md +75 -0
- data/Gemfile +38 -0
- data/Gemfile.lock +58 -0
- data/LICENSE.txt +21 -0
- data/README.md +324 -0
- data/Rakefile +13 -0
- data/bin/console +15 -0
- data/bin/setup +11 -0
- data/circle.yml +14 -0
- data/coverage/assets/0.10.0/application.css +799 -0
- data/coverage/assets/0.10.0/application.js +1707 -0
- data/coverage/assets/0.10.0/colorbox/border.png +0 -0
- data/coverage/assets/0.10.0/colorbox/controls.png +0 -0
- data/coverage/assets/0.10.0/colorbox/loading.gif +0 -0
- data/coverage/assets/0.10.0/colorbox/loading_background.png +0 -0
- data/coverage/assets/0.10.0/favicon_green.png +0 -0
- data/coverage/assets/0.10.0/favicon_red.png +0 -0
- data/coverage/assets/0.10.0/favicon_yellow.png +0 -0
- data/coverage/assets/0.10.0/loading.gif +0 -0
- data/coverage/assets/0.10.0/magnify.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/coverage/index.html +12508 -0
- data/lib/string_foundation/case.rb +102 -0
- data/lib/string_foundation/convert.rb +51 -0
- data/lib/string_foundation/convertible.rb +40 -0
- data/lib/string_foundation/like.rb +24 -0
- data/lib/string_foundation/version.rb +7 -0
- data/lib/string_foundation/with.rb +26 -0
- data/lib/string_foundation.rb +6 -0
- data/pkg/string_foundation-1.0.0.gem +0 -0
- data/spec/spec_helper.rb +40 -0
- data/spec/string_foundation/case_spec.rb +901 -0
- data/spec/string_foundation/convert_spec.rb +234 -0
- data/spec/string_foundation/convertaile_spec.rb +286 -0
- data/spec/string_foundation/like_spec.rb +218 -0
- data/spec/string_foundation/version_spec.rb +14 -0
- data/spec/string_foundation/with_spec.rb +99 -0
- data/spec/support/enhanced_matchers_extension.rb +11 -0
- data/string_foundation.gemspec +22 -0
- data/string_foundation.png +0 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 364ff7438ace10942b553e927848df3d7ca5f99d
|
4
|
+
data.tar.gz: d30ac8b18e271e3176352eeae5f9e3ab5b0f0fa9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8426ac4262df45928da1d9593e5c6189187b772999315540b73264d2e48a9ff9b1f8c6a814ec2b66fd6f493995e114d5a7d0c09b3630c50238e33bfd4ef84356
|
7
|
+
data.tar.gz: 304dc272d7c6ed55d7f98ffeea7604afe5e27b695f27ed3240da07eda117b9bbdf3fd3552c35ee305c2fcbc674840335d03ba58c679efdd9e68a6a87673196f2
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
<!-- ======================================================================= -->
|
2
|
+
<!-- CHANGELOG -->
|
3
|
+
<!-- ======================================================================= -->
|
4
|
+
# Changelog
|
5
|
+
## 1.0.0 (2017-05-09)
|
6
|
+
- Initial public release - [@jagaapple](https://github.com/jagaapple), [@cosmicphi](https://github.com/cosmicphi)
|
7
|
+
|
8
|
+
## 0.0.1 (2017-04-04)
|
9
|
+
- Initial private release - [@jagaapple](https://github.com/jagaapple)
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
<!-- ======================================================================= -->
|
2
|
+
<!-- CONTRIBUTOR COVENANT CODE OF CONDUCT -->
|
3
|
+
<!-- ======================================================================= -->
|
4
|
+
# Contributor Covenant Code of Conduct
|
5
|
+
## Our Pledge
|
6
|
+
In the interest of fostering an open and welcoming environment, we as
|
7
|
+
contributors and maintainers pledge to making participation in our project and
|
8
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
9
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
10
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
11
|
+
orientation.
|
12
|
+
|
13
|
+
|
14
|
+
## Our Standards
|
15
|
+
Examples of behavior that contributes to creating a positive environment
|
16
|
+
include:
|
17
|
+
|
18
|
+
- Using welcoming and inclusive language
|
19
|
+
- Being respectful of differing viewpoints and experiences
|
20
|
+
- Gracefully accepting constructive criticism
|
21
|
+
- Focusing on what is best for the community
|
22
|
+
- Showing empathy towards other community members
|
23
|
+
|
24
|
+
Examples of unacceptable behavior by participants include:
|
25
|
+
|
26
|
+
- The use of sexualized language or imagery and unwelcome sexual attention or
|
27
|
+
advances
|
28
|
+
- Trolling, insulting/derogatory comments, and personal or political attacks
|
29
|
+
- Public or private harassment
|
30
|
+
- Publishing others' private information, such as a physical or electronic
|
31
|
+
address, without explicit permission
|
32
|
+
- Other conduct which could reasonably be considered inappropriate in a
|
33
|
+
professional setting
|
34
|
+
|
35
|
+
|
36
|
+
## Our Responsibilities
|
37
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
38
|
+
behavior and are expected to take appropriate and fair corrective action in
|
39
|
+
response to any instances of unacceptable behavior.
|
40
|
+
|
41
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
42
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
43
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
44
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
45
|
+
threatening, offensive, or harmful.
|
46
|
+
|
47
|
+
|
48
|
+
## Scope
|
49
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
50
|
+
when an individual is representing the project or its community. Examples of
|
51
|
+
representing a project or community include using an official project e-mail
|
52
|
+
address, posting via an official social media account, or acting as an appointed
|
53
|
+
representative at an online or offline event. Representation of a project may be
|
54
|
+
further defined and clarified by project maintainers.
|
55
|
+
|
56
|
+
|
57
|
+
## Enforcement
|
58
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
59
|
+
reported by contacting the project team at s.w.nnctj@gmail.com. All
|
60
|
+
complaints will be reviewed and investigated and will result in a response that
|
61
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
62
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
63
|
+
Further details of specific enforcement policies may be posted separately.
|
64
|
+
|
65
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
66
|
+
faith may face temporary or permanent repercussions as determined by other
|
67
|
+
members of the project's leadership.
|
68
|
+
|
69
|
+
|
70
|
+
## Attribution
|
71
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
72
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
73
|
+
|
74
|
+
[homepage]: http://contributor-covenant.org
|
75
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# ==============================================================================
|
2
|
+
# GEM FILE
|
3
|
+
# ==============================================================================
|
4
|
+
# frozen_string_literal: true
|
5
|
+
source 'https://rubygems.org'
|
6
|
+
|
7
|
+
# Specify your gem's dependencies in string_foundation.gemspec.
|
8
|
+
gemspec
|
9
|
+
|
10
|
+
# ------------------------------------------------------------------------------
|
11
|
+
# For Development and Test
|
12
|
+
# ------------------------------------------------------------------------------
|
13
|
+
group :development, :test do
|
14
|
+
|
15
|
+
# Install bundler and rake.
|
16
|
+
gem 'bundler'
|
17
|
+
gem 'rake'
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
# ------------------------------------------------------------------------------
|
23
|
+
# For Test
|
24
|
+
# ------------------------------------------------------------------------------
|
25
|
+
group :test do
|
26
|
+
|
27
|
+
# Use RSpec for unit test.
|
28
|
+
gem 'rspec'
|
29
|
+
# Use a code coverage analysis tool for Ruby.
|
30
|
+
gem 'simplecov'
|
31
|
+
# Output the result of SimpleCov to a console.
|
32
|
+
gem 'simplecov-console'
|
33
|
+
# Use Codecov to get status badges.
|
34
|
+
gem 'codecov'
|
35
|
+
# Generate random text.
|
36
|
+
gem 'random_token'
|
37
|
+
|
38
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
string_foundation (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ansi (1.5.0)
|
10
|
+
codecov (0.1.10)
|
11
|
+
json
|
12
|
+
simplecov
|
13
|
+
url
|
14
|
+
diff-lcs (1.2.5)
|
15
|
+
docile (1.1.5)
|
16
|
+
hirb (0.7.3)
|
17
|
+
json (2.0.3)
|
18
|
+
rake (12.0.0)
|
19
|
+
random_token (1.1.1)
|
20
|
+
rspec (3.5.0)
|
21
|
+
rspec-core (~> 3.5.0)
|
22
|
+
rspec-expectations (~> 3.5.0)
|
23
|
+
rspec-mocks (~> 3.5.0)
|
24
|
+
rspec-core (3.5.4)
|
25
|
+
rspec-support (~> 3.5.0)
|
26
|
+
rspec-expectations (3.5.0)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.5.0)
|
29
|
+
rspec-mocks (3.5.0)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.5.0)
|
32
|
+
rspec-support (3.5.0)
|
33
|
+
simplecov (0.14.0)
|
34
|
+
docile (~> 1.1.0)
|
35
|
+
json (>= 1.8, < 3)
|
36
|
+
simplecov-html (~> 0.10.0)
|
37
|
+
simplecov-console (0.4.1)
|
38
|
+
ansi
|
39
|
+
hirb
|
40
|
+
simplecov
|
41
|
+
simplecov-html (0.10.0)
|
42
|
+
url (0.3.2)
|
43
|
+
|
44
|
+
PLATFORMS
|
45
|
+
ruby
|
46
|
+
|
47
|
+
DEPENDENCIES
|
48
|
+
bundler
|
49
|
+
codecov
|
50
|
+
rake
|
51
|
+
random_token
|
52
|
+
rspec
|
53
|
+
simplecov
|
54
|
+
simplecov-console
|
55
|
+
string_foundation!
|
56
|
+
|
57
|
+
BUNDLED WITH
|
58
|
+
1.14.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright 2017 Brushdown
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,324 @@
|
|
1
|
+
<!-- ======================================================================= -->
|
2
|
+
<!-- README -->
|
3
|
+
<!-- ======================================================================= -->
|
4
|
+
<img src="string_foundation.png" alt="String Foundation" width="600">
|
5
|
+
|
6
|
+
---
|
7
|
+
|
8
|
+
[![CircleCI](https://img.shields.io/circleci/project/github/brushdown/string_foundation.rb/master.svg)](https://circleci.com/gh/brushdown/string_foundation.rb)
|
9
|
+
[![codecov](https://img.shields.io/codecov/c/github/brushdown/string_foundation.rb/master.svg)](https://codecov.io/gh/brushdown/string_foundation.rb)
|
10
|
+
[![Gem](https://img.shields.io/gem/v/string_foundation.svg)](https://rubygems.org/gems/string_foundation/)
|
11
|
+
[![license](https://img.shields.io/github/license/brushdown/string_foundation.rb.svg)](https://opensource.org/licenses/MIT)
|
12
|
+
[![@jagaapple](https://img.shields.io/badge/contact-%40jagaapple-blue.svg)](https://twitter.com/jagaapple)
|
13
|
+
|
14
|
+
String Foundation is a Ruby library that provides useful methods for the Ruby
|
15
|
+
string class.
|
16
|
+
|
17
|
+
|
18
|
+
## Table of Contents
|
19
|
+
|
20
|
+
<!-- MarkdownTOC autolink="true" bracket="round" -->
|
21
|
+
|
22
|
+
- [Quick Start](#quick-start)
|
23
|
+
- [Requirements](#requirements)
|
24
|
+
- [Installation](#installation)
|
25
|
+
- [Basic Usage](#basic-usage)
|
26
|
+
- [The Convertible Methods](#the-convertible-methods)
|
27
|
+
- [To Integer](#to-integer)
|
28
|
+
- [To Float](#to-float)
|
29
|
+
- [To TrueClass / FalseClass](#to-trueclass--falseclass)
|
30
|
+
- [The With Methods](#the-with-methods)
|
31
|
+
- [Remove Leading Zeros \(Zero Padding\)](#remove-leading-zeros-zero-padding)
|
32
|
+
- [The Convert Methods](#the-convert-methods)
|
33
|
+
- [To TrueClass / FalseClass](#to-trueclass--falseclass-1)
|
34
|
+
- [To Proper Class](#to-proper-class)
|
35
|
+
- [Newlines To Characters](#newlines-to-characters)
|
36
|
+
- [The Like Methods](#the-like-methods)
|
37
|
+
- [Like Integer](#like-integer)
|
38
|
+
- [Like Float](#like-float)
|
39
|
+
- [The Case Methods](#the-case-methods)
|
40
|
+
- [Contributing to String Foundation](#contributing-to-string-foundation)
|
41
|
+
- [License](#license)
|
42
|
+
|
43
|
+
<!-- /MarkdownTOC -->
|
44
|
+
|
45
|
+
|
46
|
+
## Quick Start
|
47
|
+
### Requirements
|
48
|
+
- Ruby version 2.1.0 or higher
|
49
|
+
- A project that uses source control, such as Git
|
50
|
+
|
51
|
+
### Installation
|
52
|
+
String Foundation is available as a gem, to install it just install the gem:
|
53
|
+
|
54
|
+
```bash
|
55
|
+
$ gem install string_foundation
|
56
|
+
```
|
57
|
+
|
58
|
+
If you are using Bundler, add this line to your application's Gemfile:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
gem 'string_foundation'
|
62
|
+
```
|
63
|
+
|
64
|
+
And then run `bundle install` .
|
65
|
+
|
66
|
+
### Basic Usage
|
67
|
+
The following is a sample of what String Foundation provides.
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
# Check for convertible.
|
71
|
+
'123'.to_i? #=> true
|
72
|
+
'x123'.to_i? #=> false
|
73
|
+
|
74
|
+
# Remove leading zeros.
|
75
|
+
'00000123'.without_leading_zeros #=> '123'
|
76
|
+
|
77
|
+
# Convert a value to the appropriate type.
|
78
|
+
'false'.to_pretty #=> false
|
79
|
+
'.5'.to_pretty #=> 0.5
|
80
|
+
|
81
|
+
# Convert to lowerCamelCase.
|
82
|
+
'user_id'.to_lcamel #=> 'userId'
|
83
|
+
```
|
84
|
+
|
85
|
+
|
86
|
+
## The Convertible Methods
|
87
|
+
The Convertible Methods enable you to check whether or not a string can be
|
88
|
+
converted to another class object. These methods return `true` or `false` .
|
89
|
+
|
90
|
+
### To Integer
|
91
|
+
The `to_i?` method checks whether a string can be converted to an Integer
|
92
|
+
(including Fixnum and Bignum classes). This returns `true` only if an argument
|
93
|
+
is convertible, therefore it is not required for the argument to be an integral
|
94
|
+
number. If you pass a floating point number as an argument to this method, it will
|
95
|
+
return `true` because it can be converted using the `to_i` Ruby built-in method
|
96
|
+
(for example, `'0.4'.to_i` returns `0` ).
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
'123'.to_i? #=> true
|
100
|
+
'0.3'.to_i? #=> true
|
101
|
+
'.2'.to_i? #=> true
|
102
|
+
|
103
|
+
'abc'.to_i? #=> false
|
104
|
+
'2x'.to_i? #=> false
|
105
|
+
```
|
106
|
+
|
107
|
+
If an argument has leading zeros, they will be removed before checking.
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
'00000123'.to_i? #=> true
|
111
|
+
```
|
112
|
+
|
113
|
+
### To Float
|
114
|
+
The `to_f?` method is to check convertibility to the Float class. This returns
|
115
|
+
`true` only when an argument is convertible, therefore it is not required for the
|
116
|
+
argument to be a floating point number. If you pass an integral number as an
|
117
|
+
argument to this method, it will return `true` because it can be converted using
|
118
|
+
the `to_f` Ruby built-in method (for example, `'2'.to_f` returns `2.0` ).
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
'0.3'.to_f? #=> true
|
122
|
+
'2'.to_f? #=> true
|
123
|
+
'.2'.to_f? #=> true
|
124
|
+
|
125
|
+
'abc'.to_f? #=> false
|
126
|
+
'2.0x'.to_f? #=> false
|
127
|
+
```
|
128
|
+
|
129
|
+
|
130
|
+
### To TrueClass / FalseClass
|
131
|
+
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 `'true'` or
|
133
|
+
`'false'` .
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
'true'.to_bool? #=> true
|
137
|
+
'false'.to_bool? #=> true
|
138
|
+
|
139
|
+
'abc'.to_bool? #=> false
|
140
|
+
'123'.to_bool? #=> false
|
141
|
+
```
|
142
|
+
|
143
|
+
String Foundation also provides a check for a string's convertibility to a "Booly"
|
144
|
+
(truthy or falsy). This returns `true` only when the string is a positive number,
|
145
|
+
`'true'` , or an empty string. If not, it returns `false` .
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
'true'.to_booly? #=> true
|
149
|
+
'123'.to_booly? #=> true
|
150
|
+
''.to_booly? #=> true
|
151
|
+
'-3'.to_booly? #=> true
|
152
|
+
|
153
|
+
'abc'.to_booly? #=> false
|
154
|
+
```
|
155
|
+
|
156
|
+
|
157
|
+
## The With Methods
|
158
|
+
The With Methods provide you with ways to append or remove specific characters
|
159
|
+
from a String object.
|
160
|
+
|
161
|
+
### Remove Leading Zeros (Zero Padding)
|
162
|
+
The `without_leading_zeros` method removes leading zeros (called "zero padding").
|
163
|
+
This supports a floating point number and a string starting with a plus or minus sign.
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
'00001'.without_leading_zeros #=> '1'
|
167
|
+
'-0000.3'.without_leading_zeros #=> '-0.3'
|
168
|
+
|
169
|
+
%w(00001 00003 00008).map { |num| num.without_leading_zeros } #=> ['1', '3', '8']
|
170
|
+
```
|
171
|
+
|
172
|
+
|
173
|
+
## The Convert Methods
|
174
|
+
The Convert Methods enable you to convert to a specific class object. While Ruby
|
175
|
+
built-in methods include conversion from a String object to an Integer object or
|
176
|
+
a Float object, they do not include conversion to a TrueClass / FalseClass object
|
177
|
+
or a proper class object. The Convert Methods make it easy to convert to these
|
178
|
+
excluded classes.
|
179
|
+
|
180
|
+
### To TrueClass / FalseClass
|
181
|
+
The `to_bool` method is for converting from a `'true'` or `'false'` string to `true`
|
182
|
+
or `false` , otherwise it will raise a `TypeError` .
|
183
|
+
|
184
|
+
```ruby
|
185
|
+
'true'.to_bool #=> true
|
186
|
+
'false'.to_bool #=> false
|
187
|
+
|
188
|
+
'1'.to_bool #=> TypeError
|
189
|
+
'0'.to_bool #=> TypeError
|
190
|
+
'-1'.to_bool #=> TypeError
|
191
|
+
'abc'.to_bool #=> TypeError
|
192
|
+
''.to_bool #=> TypeError
|
193
|
+
```
|
194
|
+
|
195
|
+
If you want to convert a Booly string, you can use the `to_booly` method. When a
|
196
|
+
string is `'true'` or a positive number, this method will return `true` . Otherwise
|
197
|
+
it will return `false` .
|
198
|
+
|
199
|
+
```ruby
|
200
|
+
'true'.to_booly #=> true
|
201
|
+
'false'.to_booly #=> false
|
202
|
+
|
203
|
+
'1'.to_booly #=> true
|
204
|
+
'0'.to_booly #=> false
|
205
|
+
'-1'.to_booly #=> false
|
206
|
+
'abc'.to_booly #=> TypeError
|
207
|
+
''.to_booly #=> false
|
208
|
+
```
|
209
|
+
|
210
|
+
### To Proper Class
|
211
|
+
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 `'true'`, or returns
|
213
|
+
an Integer `1` when a string is `'1'`.
|
214
|
+
Also this returns `nil` when a string is an empty string.
|
215
|
+
|
216
|
+
```ruby
|
217
|
+
'1'.to_pretty #=> 1
|
218
|
+
'-3'.to_pretty #=> -3
|
219
|
+
'0004'.to_pretty #=> 4
|
220
|
+
'0.1'.to_pretty #=> 0.1
|
221
|
+
'-.5'.to_pretty #=> -0.5
|
222
|
+
'00.01'.to_pretty #=> 0.01
|
223
|
+
|
224
|
+
'true'.to_pretty #=> true
|
225
|
+
'false'.to_pretty #=> false
|
226
|
+
|
227
|
+
''.to_pretty #=> nil
|
228
|
+
```
|
229
|
+
|
230
|
+
### Newlines To Characters
|
231
|
+
The `nl_to` method converts a string with newlines to its specific characters.
|
232
|
+
The `nl2` method is an alias for `nl_to` .
|
233
|
+
|
234
|
+
```ruby
|
235
|
+
"Hi!\nWe are Brushdown.".nl_to(' / ') #=> 'Hi! / We are Brushdown.'
|
236
|
+
"Hi!\nWe are Brushdown.".nl2(' / ') #=> 'Hi! / We are Brushdown.'
|
237
|
+
```
|
238
|
+
|
239
|
+
The `nl_to_br` method replaces the newlines in a string with HTML tag `<br>` for
|
240
|
+
break line.
|
241
|
+
The `nl2br` method is an alias for `nl_to_br` .
|
242
|
+
|
243
|
+
```ruby
|
244
|
+
"Hi!\nWe are Brushdown.".nl_to_br #=> 'Hi!<br>We are Brushdown.'
|
245
|
+
"Hi!\nWe are Brushdown.".nl2br #=> 'Hi!<br>We are Brushdown.'
|
246
|
+
```
|
247
|
+
|
248
|
+
|
249
|
+
## The Like Methods
|
250
|
+
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 `'000123'`
|
252
|
+
is regarded as an integral number. These method return `true` or `false` .
|
253
|
+
|
254
|
+
The Like Methods check whether a string is an integral number or a floating point
|
255
|
+
number. These methods ignore leading zeros, so the string `000123` is regarded
|
256
|
+
as an integral number. These methods return `true` or `false` .
|
257
|
+
|
258
|
+
### Like Integer
|
259
|
+
The `like_i?` method checks whether a string is an integral number.
|
260
|
+
|
261
|
+
```ruby
|
262
|
+
'123'.like_i? #=> true
|
263
|
+
'00123'.like_i? #=> true
|
264
|
+
'0.3'.like_i? #=> false
|
265
|
+
'.2'.like_i? #=> false
|
266
|
+
|
267
|
+
'abc'.like_i? #=> false
|
268
|
+
'2x'.like_i? #=> false
|
269
|
+
```
|
270
|
+
|
271
|
+
### Like Float
|
272
|
+
The `like_f?` method checks whether a string is a floating point number.
|
273
|
+
|
274
|
+
```ruby
|
275
|
+
'123'.like_f? #=> false
|
276
|
+
'00123'.like_f? #=> false
|
277
|
+
'0.3'.like_f? #=> true
|
278
|
+
'.2'.like_f? #=> true
|
279
|
+
|
280
|
+
'abc'.like_f? #=> false
|
281
|
+
'2x'.like_f? #=> false
|
282
|
+
```
|
283
|
+
|
284
|
+
|
285
|
+
## The Case Methods
|
286
|
+
The Case Methods convert to a case style, such as `lowerCamelCase` and
|
287
|
+
`lower_snake_case` . The following methods are available.
|
288
|
+
|
289
|
+
| METHOD NAME | CASE STYLE | EXAMPLE |
|
290
|
+
|:------------|:------------------------------|:-------------------|
|
291
|
+
| `to_lcamel` | Lower Camel Case | `weAreBrushdown` |
|
292
|
+
| `to_ucamel` | Upper Camel Case | `WeAreBrushdown` |
|
293
|
+
| `to_lsnake` | Lower Snake Case | `we_are_brushdown` |
|
294
|
+
| `to_usnake` | Upper Snake Case () | `We_Are_Brushdown` |
|
295
|
+
| `to_lkebab` | Lower Kebab Case (Chain Case) | `we-are-brushdown` |
|
296
|
+
| `to_ukebab` | Upper Kebab Case (Train Case) | `We-Are-Brushdown` |
|
297
|
+
| `to_lspace` | Lower Space Case (Lower Case) | `we are brushdown` |
|
298
|
+
| `to_uspace` | Upper Space Case (Start Case) | `We Are Brushdown` |
|
299
|
+
| `to_ldot` | Lower Dot Case | `we.are.brushdown` |
|
300
|
+
| `to_udot` | Upper Dot Case | `We.Are.Brushdown` |
|
301
|
+
|
302
|
+
```ruby
|
303
|
+
'user_id'.to_lcamel #=> 'userId'
|
304
|
+
'createdAt'.to_lsnake #=> 'created_at'
|
305
|
+
```
|
306
|
+
|
307
|
+
|
308
|
+
## Contributing to String Foundation
|
309
|
+
Bug reports and pull requests are welcome on GitHub at
|
310
|
+
[https://github.com/brushdown/string_foundation.rb](https://github.com/brushdown/string_foundation.rb).
|
311
|
+
This project is intended to be a safe, welcoming space for collaboration, and
|
312
|
+
contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org)
|
313
|
+
code of conduct.
|
314
|
+
|
315
|
+
We adhere GitHub Flow to develop this project. Anything in the `master` branch
|
316
|
+
is deployable. To work on something new, create a descriptively named branch
|
317
|
+
off of master, also add a prefix `feature/` to its name.
|
318
|
+
For more details, see [GitHub Flow – Scott Chacon](http://scottchacon.com/2011/08/31/github-flow.html).
|
319
|
+
|
320
|
+
|
321
|
+
## License
|
322
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
323
|
+
|
324
|
+
Copyright 2017 Jaga Apple and Brushdown. All rights reserved.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# ==============================================================================
|
2
|
+
# RAKE FILE
|
3
|
+
# ==============================================================================
|
4
|
+
# frozen_string_literal: true
|
5
|
+
require 'bundler/gem_tasks'
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
|
8
|
+
# ------------------------------------------------------------------------------
|
9
|
+
# Configure Tasks
|
10
|
+
# ------------------------------------------------------------------------------
|
11
|
+
# Set a RSpec task.
|
12
|
+
RSpec::Core::RakeTask.new(:spec)
|
13
|
+
task default: :spec
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# ==============================================================================
|
3
|
+
# BIN - CONSOLE
|
4
|
+
# ==============================================================================
|
5
|
+
require "bundler/setup"
|
6
|
+
require "string_foundation"
|
7
|
+
|
8
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
9
|
+
# with your gem easier. You can also use a different console, if you like.
|
10
|
+
|
11
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
12
|
+
# require "pry"
|
13
|
+
# Pry.start
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# ==============================================================================
|
2
|
+
# BIN - SETUP
|
3
|
+
# ==============================================================================
|
4
|
+
#!/usr/bin/env bash
|
5
|
+
set -euo pipefail
|
6
|
+
IFS=$'\n\t'
|
7
|
+
set -vx
|
8
|
+
|
9
|
+
bundle install
|
10
|
+
|
11
|
+
# Do any other automated setup that you need to do here.
|
data/circle.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# ==============================================================================
|
2
|
+
# CIRCLE
|
3
|
+
# ==============================================================================
|
4
|
+
# Settings for CircleCI.
|
5
|
+
machine:
|
6
|
+
environment:
|
7
|
+
CI: true
|
8
|
+
dependencies:
|
9
|
+
pre:
|
10
|
+
- 'case $CIRCLE_NODE_INDEX in 0) rvm use 2.1.0 --default ;; 1) rvm use 2.4.1 --default ;; esac'
|
11
|
+
test:
|
12
|
+
override:
|
13
|
+
- ruby -v ; bundle exec rspec:
|
14
|
+
parallel: true
|