refinements 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +17 -1
- data/lib/refinements/hash_extensions.rb +8 -0
- data/lib/refinements/identity.rb +2 -2
- data/lib/refinements/string_extensions.rb +21 -0
- metadata +60 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: faad3c26379c1127712352171816ea9d1b5af818
|
4
|
+
data.tar.gz: 5b0015ee018018cbceee2d7b78860274024391cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6f57fa867c72788d3a849f548a7424b09da5ea2e7f853c12c225fa65e34de33240130d171b68104afeb865f927cd0f51df2cff398b8da8bb51e04ea6f30fba4
|
7
|
+
data.tar.gz: 655188f3e03eec802b3968d31b7b1b79755fa28e26f7c92925d072ad8a9153812aeee4e593f93f00e9428e629b033742e87739ee3081cb93be746da936632e51
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -20,6 +20,7 @@ Provides a collection of refinements for core Ruby objects.
|
|
20
20
|
- [Requires](#requires)
|
21
21
|
- [Using](#using)
|
22
22
|
- [Examples](#examples)
|
23
|
+
- [String](#string)
|
23
24
|
- [Big Decimal](#big-decimal)
|
24
25
|
- [Array](#array)
|
25
26
|
- [Hash](#hash)
|
@@ -41,10 +42,16 @@ Provides a collection of refinements for core Ruby objects.
|
|
41
42
|
- `Array#compress` - Removes nil and empty values without modifying itself.
|
42
43
|
- `Array#compress!` - Removes nil and empty values and modifies itself.
|
43
44
|
- Adds Hash refinements:
|
45
|
+
- `#compact` - Removes key/value pairs with nil values without modifying itself.
|
46
|
+
- `#compact!` - Removes key/value pairs with nil values and modifies itself.
|
44
47
|
- `#deep_merge` - Merges deeply nested hashes together without itself.
|
45
48
|
- `#deep_merge!` - Merges deeply nested hashes together and modifies itself.
|
46
49
|
- `#reverse_merge` - Merges calling hash into passed in hash without modifying calling hash.
|
47
50
|
- `#reverse_merge!` - Merges calling hash into passed in hash and modifies calling hash.
|
51
|
+
- Adds String refinements:
|
52
|
+
- `#camelcase` - Answers a camelcased string. Example: "ThisIsCamelcase".
|
53
|
+
- `#snakecase` - Answers a snakecased string. Example: "this_is_snakecase".
|
54
|
+
- `#titleize` - Answers titleized string. Example: "This Is Titleized".
|
48
55
|
|
49
56
|
# Requirements
|
50
57
|
|
@@ -55,7 +62,7 @@ Provides a collection of refinements for core Ruby objects.
|
|
55
62
|
|
56
63
|
For a secure install, type the following from the command line (recommended):
|
57
64
|
|
58
|
-
gem cert --add <(curl
|
65
|
+
gem cert --add <(curl --location --silent https://www.alchemists.io/gem-public.pem)
|
59
66
|
gem install refinements --trust-policy MediumSecurity
|
60
67
|
|
61
68
|
NOTE: A HighSecurity trust policy would be best but MediumSecurity enables signed gem verification while
|
@@ -77,6 +84,7 @@ Due to this gem being a collection of Ruby refinements, none of the refinements
|
|
77
84
|
reduce code bloat for your app. Instead, require the specific requirement for the code that needs it. You'll want to
|
78
85
|
require one or all of the following:
|
79
86
|
|
87
|
+
require "refinements/string_extensions"
|
80
88
|
require "refinements/big_decimal_extensions"
|
81
89
|
require "refinements/array_extensions"
|
82
90
|
require "refinements/hash_extensions"
|
@@ -87,6 +95,7 @@ In addition to requiring the appropriate refinement file for the code that needs
|
|
87
95
|
refinement by using the `using` keyword within your object. You'll want to use one or all of the following:
|
88
96
|
|
89
97
|
class Example
|
98
|
+
using Refinements::StringExtensions
|
90
99
|
using Refinements::BigDecimalExtensions
|
91
100
|
using Refinements::ArrayExtensions
|
92
101
|
using Refinements::HashExtensions
|
@@ -97,6 +106,13 @@ refinement by using the `using` keyword within your object. You'll want to use o
|
|
97
106
|
With the appropriate refinements required and used within your objects, the following sections demonstrates how each
|
98
107
|
refinement enriches your objects with new capabilities.
|
99
108
|
|
109
|
+
### String
|
110
|
+
|
111
|
+
example = "This is-an EXAMPLE"
|
112
|
+
example.camelcase # => "ThisIsAnExample"
|
113
|
+
example.snakecase # => "this_is_an_example"
|
114
|
+
example.titleize # => "This Is An Example"
|
115
|
+
|
100
116
|
### Big Decimal
|
101
117
|
|
102
118
|
big = BigDecimal.new "5.0E-10"
|
data/lib/refinements/identity.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Refinements
|
4
|
+
# Refinements for Strings.
|
5
|
+
module StringExtensions
|
6
|
+
refine String do
|
7
|
+
def camelcase
|
8
|
+
return self if self =~ /\A[a-zA-Z]{1,}\z/ && self !~ /\A[A-Z]{1,}\z/
|
9
|
+
snakecase.split("_").map(&:capitalize).join ""
|
10
|
+
end
|
11
|
+
|
12
|
+
def snakecase
|
13
|
+
downcase.gsub(/[^a-z]/, "_").squeeze "_"
|
14
|
+
end
|
15
|
+
|
16
|
+
def titleize
|
17
|
+
snakecase.split("_").map(&:capitalize).join " "
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: refinements
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brooke Kuhlmann
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
aSif+qBc6oHD7EQWPF5cZkzkIURuwNwPBngZGxIKaMAgRhjGFXzUMAaq++r59cS9
|
31
31
|
xTfQ4k6fglKEgpnLAXiKdo2c8Ym+X4rIKFfedQ==
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2016-
|
33
|
+
date: 2016-04-20 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: rake
|
@@ -144,6 +144,62 @@ dependencies:
|
|
144
144
|
- - ">="
|
145
145
|
- !ruby/object:Gem::Version
|
146
146
|
version: '0'
|
147
|
+
- !ruby/object:Gem::Dependency
|
148
|
+
name: bond
|
149
|
+
requirement: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
type: :development
|
155
|
+
prerelease: false
|
156
|
+
version_requirements: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
- !ruby/object:Gem::Dependency
|
162
|
+
name: wirb
|
163
|
+
requirement: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
type: :development
|
169
|
+
prerelease: false
|
170
|
+
version_requirements: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
- !ruby/object:Gem::Dependency
|
176
|
+
name: hirb
|
177
|
+
requirement: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - ">="
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
type: :development
|
183
|
+
prerelease: false
|
184
|
+
version_requirements: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
- !ruby/object:Gem::Dependency
|
190
|
+
name: awesome_print
|
191
|
+
requirement: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - ">="
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: '0'
|
196
|
+
type: :development
|
197
|
+
prerelease: false
|
198
|
+
version_requirements: !ruby/object:Gem::Requirement
|
199
|
+
requirements:
|
200
|
+
- - ">="
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: '0'
|
147
203
|
- !ruby/object:Gem::Dependency
|
148
204
|
name: rspec
|
149
205
|
requirement: !ruby/object:Gem::Requirement
|
@@ -258,6 +314,7 @@ files:
|
|
258
314
|
- lib/refinements/big_decimal_extensions.rb
|
259
315
|
- lib/refinements/hash_extensions.rb
|
260
316
|
- lib/refinements/identity.rb
|
317
|
+
- lib/refinements/string_extensions.rb
|
261
318
|
- lib/tasks/console.rake
|
262
319
|
- lib/tasks/rspec.rake
|
263
320
|
- lib/tasks/rubocop.rake
|
@@ -281,7 +338,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
281
338
|
version: '0'
|
282
339
|
requirements: []
|
283
340
|
rubyforge_project:
|
284
|
-
rubygems_version: 2.
|
341
|
+
rubygems_version: 2.6.3
|
285
342
|
signing_key:
|
286
343
|
specification_version: 4
|
287
344
|
summary: Provides a collection of refinements for core Ruby objects.
|
metadata.gz.sig
CHANGED
Binary file
|