finishing_moves 1.0.1 → 1.2.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 +5 -5
- data/.travis.yml +5 -6
- data/README.md +8 -8
- data/Vagrantfile +2 -2
- data/finishing_moves.gemspec +2 -5
- data/lib/finishing_moves/hash.rb +7 -0
- data/lib/finishing_moves/string.rb +11 -0
- data/lib/finishing_moves/version.rb +1 -1
- data/provision.sh +12 -3
- data/spec/hash_spec.rb +14 -0
- data/spec/spec_helper.rb +0 -4
- data/spec/string_spec.rb +21 -0
- metadata +13 -51
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a791dce174d28e7ddf84f7a277f928ad75e5fafe2077d0be9f7650fb05cd56ab
|
4
|
+
data.tar.gz: 85b42fa2e461a88cb3a3a733422b27907ed1a17fedfdb8473f27afc6206c3404
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54f153a89bbdbc16aaaae04f935b2a405b15e8a61885ab509558212010dff1775d2a6957628f9faddd65a03134b0308ce1cb1a3a59a123dda616145415dcde1d
|
7
|
+
data.tar.gz: d21e8d643d14e507714d95f622c3a95bb61d5c31f4f6549ae52dfb249041e324beed6aeff0eedd49da2bf86a8becb9ee64d4cffbd4dab43689ef214b7d49e476
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Finishing Moves
|
2
2
|
[](https://rubygems.org/gems/finishing_moves)
|
3
3
|
[](https://travis-ci.org/forgecrafted/finishing_moves)
|
4
|
+
[](https://github.com/markets/awesome-ruby)
|
4
5
|
|
5
6
|
Ruby includes a huge amount of default awesomeness that tackles most common development challenges. But every now and then, you find yourself performing contortions to achieve results that, honestly, **should feel more natural** given the language's design elegance. Finishing Moves is a collection of methods designed to assist in those "why is this awkward?" scenarios.
|
6
7
|
|
@@ -25,8 +26,8 @@ gem install 'finishing_moves'
|
|
25
26
|
- [`Array#to_hash_values`](https://github.com/forgecrafted/finishing_moves/wiki/Array#arrayto_hash_values) :boom:
|
26
27
|
- [`Array#to_indexed_hash`](https://github.com/forgecrafted/finishing_moves/wiki/Array#arrayto_indexed_hash)
|
27
28
|
- [`Array#to_hash_keys`](https://github.com/forgecrafted/finishing_moves/wiki/Array#arrayto_hash_keys)
|
28
|
-
- [`Array#to_sym_strict`](https://github.com/forgecrafted/finishing_moves/wiki/Array#arrayto_sym_strict)
|
29
|
-
- [`Array#to_sym_loose`](https://github.com/forgecrafted/finishing_moves/wiki/Array#arrayto_sym_loose)
|
29
|
+
- [`Array#to_sym_strict`](https://github.com/forgecrafted/finishing_moves/wiki/Array#arrayto_sym_strict)
|
30
|
+
- [`Array#to_sym_loose`](https://github.com/forgecrafted/finishing_moves/wiki/Array#arrayto_sym_loose)
|
30
31
|
- [`Enumerable#key_map`](https://github.com/forgecrafted/finishing_moves/wiki/Enumerable#enumerablekey_map) :boom:
|
31
32
|
- [`Enumerable#key_map_reduce`](https://github.com/forgecrafted/finishing_moves/wiki/Enumerable#enumerablekey_map_reduce)
|
32
33
|
- [`Hash#delete!`](https://github.com/forgecrafted/finishing_moves/wiki/Hash#hashdelete)
|
@@ -34,6 +35,8 @@ gem install 'finishing_moves'
|
|
34
35
|
- [`Hash#delete_each!`](https://github.com/forgecrafted/finishing_moves/wiki/Hash#hashdelete_each-1)
|
35
36
|
- [`Integer#length`](https://github.com/forgecrafted/finishing_moves/wiki/Numeric#integerlength)
|
36
37
|
- [`Kernel#nil_chain`](https://github.com/forgecrafted/finishing_moves/wiki/Kernel#kernelnil_chain) :boom::boom:
|
38
|
+
- [`Kernel#bool_chain`](https://github.com/forgecrafted/finishing_moves/wiki/Kernel#kernelbool_chain)
|
39
|
+
- [`Kernel#silently`](https://github.com/forgecrafted/finishing_moves/wiki/Kernel#kernelsilently)
|
37
40
|
- [`Kernel#cascade`](https://github.com/forgecrafted/finishing_moves/wiki/Kernel#kernelcascade)
|
38
41
|
- [`Kernel#class_exists?`](https://github.com/forgecrafted/finishing_moves/wiki/Kernel#kernelclass_exists)
|
39
42
|
- [`Numeric#add_percent`](https://github.com/forgecrafted/finishing_moves/wiki/Numeric#numericadd_percent)
|
@@ -58,15 +61,12 @@ gem install 'finishing_moves'
|
|
58
61
|
- [`String#remove_whitespace`](https://github.com/forgecrafted/finishing_moves/wiki/String#stringremove_whitespace)
|
59
62
|
- [`String#replace_whitespace`](https://github.com/forgecrafted/finishing_moves/wiki/String#stringreplace_whitespace)
|
60
63
|
- [`String#strip_all`](https://github.com/forgecrafted/finishing_moves/wiki/String#stringstrip_all) :boom:
|
61
|
-
|
62
|
-
*
|
63
|
-
|
64
|
-
- [Boolean Typecasting](https://github.com/forgecrafted/finishing_moves/wiki/Boolean-Typecasting)
|
65
|
-
- ~Fiscal Calendar Calculations~ Moved to its own gem! [Check out Fiscally.](https://github.com/forgecrafted/fiscally)
|
64
|
+
- [`String#to_uuid`](https://github.com/forgecrafted/finishing_moves/wiki/String#stringto_uuid)
|
65
|
+
- [Boolean Typecasting](https://github.com/forgecrafted/finishing_moves/wiki/Boolean-Typecasting) (*multi-class enhancement*)
|
66
66
|
|
67
67
|
### Ruby Version
|
68
68
|
|
69
|
-
Tested against **`2.
|
69
|
+
Tested against all supported versions of official RVM, currently **`2.5.0` and above**.
|
70
70
|
|
71
71
|
## Development approach
|
72
72
|
|
data/Vagrantfile
CHANGED
@@ -6,7 +6,7 @@ FQDN = "#{NAME}.example.com"
|
|
6
6
|
|
7
7
|
Vagrant.configure("2") do |config|
|
8
8
|
# "trusty" is 14.04
|
9
|
-
config.vm.box = "ubuntu/
|
9
|
+
config.vm.box = "ubuntu/focal64"
|
10
10
|
|
11
11
|
# Use the normal insecure key
|
12
12
|
# https://github.com/mitchellh/vagrant/issues/2608
|
@@ -18,7 +18,7 @@ Vagrant.configure("2") do |config|
|
|
18
18
|
"--name", NAME,
|
19
19
|
"--memory", 4096,
|
20
20
|
# I/O APIC must be enabled to support a multi-core guest.
|
21
|
-
"--cpus",
|
21
|
+
"--cpus", 2,
|
22
22
|
"--ioapic", "on",
|
23
23
|
# Enable native host virtualization features (yields better performance).
|
24
24
|
"--pae", "on",
|
data/finishing_moves.gemspec
CHANGED
@@ -19,13 +19,10 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.files = `git ls-files -z`.split("\x0")
|
20
20
|
s.test_files = Dir["spec/**/*"]
|
21
21
|
|
22
|
-
s.add_development_dependency 'rb-readline', '>= 0'
|
23
22
|
s.add_development_dependency 'rspec', '~> 3.1.0'
|
24
|
-
s.add_development_dependency 'priscilla', '>= 0'
|
25
|
-
s.add_development_dependency 'pry-byebug', '>= 0'
|
26
23
|
s.add_development_dependency 'fuubar', '>= 0'
|
27
|
-
s.add_development_dependency 'coveralls', '>= 0
|
24
|
+
s.add_development_dependency 'coveralls', '>= 0'
|
28
25
|
|
29
|
-
s.required_ruby_version = '>= 2.
|
26
|
+
s.required_ruby_version = '>= 2.7.0'
|
30
27
|
|
31
28
|
end
|
data/lib/finishing_moves/hash.rb
CHANGED
@@ -94,6 +94,17 @@ class String
|
|
94
94
|
match(pattern, pos).not_nil?
|
95
95
|
end
|
96
96
|
|
97
|
+
def to_uuid
|
98
|
+
if length == 36 && self.match?(/^[0-9A-F-]+$/i)
|
99
|
+
return self
|
100
|
+
elsif length == 32 && self.match?(/^[0-9A-F]+$/i)
|
101
|
+
str = self.dup
|
102
|
+
return str[0,8] + '-' +str[8,4] + '-' +str[12,4] + '-' +str[16,4] + '-' +str[20,12]
|
103
|
+
else
|
104
|
+
raise ArgumentError, "#{self} is not a valid UUID"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
97
108
|
# TODO
|
98
109
|
# def each_char_index(&block)
|
99
110
|
# how to return enumerator if no block given?
|
data/provision.sh
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# Shell user settings.
|
4
4
|
USER_NAME=vagrant
|
5
5
|
USER_HOME=/home/$USER_NAME
|
6
|
-
DEFAULT_RUBY='
|
6
|
+
DEFAULT_RUBY='3.1.2'
|
7
7
|
|
8
8
|
###############################################################################
|
9
9
|
# Functions
|
@@ -27,7 +27,7 @@ apt-get -yfV dist-upgrade
|
|
27
27
|
###############################################################################
|
28
28
|
|
29
29
|
# Install dependencies.
|
30
|
-
apt-get install -yfV \
|
30
|
+
sudo apt-get install -yfV \
|
31
31
|
build-essential \
|
32
32
|
curl \
|
33
33
|
git-core \
|
@@ -38,9 +38,18 @@ apt-get install -yfV \
|
|
38
38
|
libxml2-dev \
|
39
39
|
libxslt1-dev \
|
40
40
|
libyaml-dev \
|
41
|
-
|
41
|
+
software-properties-common \
|
42
42
|
sqlite3 \
|
43
43
|
zlib1g-dev \
|
44
|
+
autoconf \
|
45
|
+
bison \
|
46
|
+
libreadline6-dev \
|
47
|
+
libncurses5-dev \
|
48
|
+
libffi-dev \
|
49
|
+
libgdbm6 \
|
50
|
+
libgdbm-dev \
|
51
|
+
libdb-dev \
|
52
|
+
uuid-dev
|
44
53
|
|
45
54
|
# Install rbenv and ruby-build.
|
46
55
|
as_user "git clone https://github.com/sstephenson/rbenv.git $USER_HOME/.rbenv"
|
data/spec/hash_spec.rb
CHANGED
@@ -27,4 +27,18 @@ describe Hash do
|
|
27
27
|
expect(test_hash.delete_each!(:baz)).to eq({ })
|
28
28
|
end
|
29
29
|
|
30
|
+
it '#sample' do
|
31
|
+
test_hash = {
|
32
|
+
"Eastern Time (US & Canada)" => "America/New_York",
|
33
|
+
"Central Time (US & Canada)" => "America/Chicago",
|
34
|
+
"Mountain Time (US & Canada)" => "America/Denver",
|
35
|
+
"Pacific Time (US & Canada)" => "America/Los_Angeles",
|
36
|
+
"Indiana (East)" => "America/Indiana/Indianapolis",
|
37
|
+
"Arizona" => "America/Phoenix",
|
38
|
+
}
|
39
|
+
test_hash_clone = test_hash.dup
|
40
|
+
test_hash.sample
|
41
|
+
|
42
|
+
end
|
43
|
+
|
30
44
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/string_spec.rb
CHANGED
@@ -256,4 +256,25 @@ describe String do
|
|
256
256
|
expect{ '12345678'.slugify! }.not_to raise_error
|
257
257
|
end
|
258
258
|
|
259
|
+
it '#to_uuid' do
|
260
|
+
str = "5062754996b140c8b5dde7ffc23376a1"
|
261
|
+
expect(str.to_uuid).to eq "50627549-96b1-40c8-b5dd-e7ffc23376a1"
|
262
|
+
# too long
|
263
|
+
expect{ (str + '1').to_uuid }.to raise_error(ArgumentError)
|
264
|
+
# not hex
|
265
|
+
expect{ (str[0,31] + 'k').to_uuid }.to raise_error(ArgumentError)
|
266
|
+
# just bad
|
267
|
+
expect{ ("just some writing 123!").to_uuid }.to raise_error(ArgumentError)
|
268
|
+
|
269
|
+
formatted_uuid = "5a658838-7aa4-488c-98f1-21805a5d2021"
|
270
|
+
expect(formatted_uuid.to_uuid).to eq formatted_uuid
|
271
|
+
# Only dashes are accepted as separators
|
272
|
+
expect{ formatted_uuid.gsub('-', ' ').to_uuid }.to raise_error(ArgumentError)
|
273
|
+
expect{ formatted_uuid.gsub('-', '.').to_uuid }.to raise_error(ArgumentError)
|
274
|
+
|
275
|
+
random_uuid = SecureRandom.uuid
|
276
|
+
no_dashes = random_uuid.delete('-')
|
277
|
+
expect(no_dashes.to_uuid).to eq random_uuid
|
278
|
+
end
|
279
|
+
|
259
280
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: finishing_moves
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank Koehl
|
@@ -9,22 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-08-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: rb-readline
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - ">="
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '0'
|
21
|
-
type: :development
|
22
|
-
prerelease: false
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - ">="
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: '0'
|
28
14
|
- !ruby/object:Gem::Dependency
|
29
15
|
name: rspec
|
30
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,34 +25,6 @@ dependencies:
|
|
39
25
|
- - "~>"
|
40
26
|
- !ruby/object:Gem::Version
|
41
27
|
version: 3.1.0
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: priscilla
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
45
|
-
requirements:
|
46
|
-
- - ">="
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: '0'
|
49
|
-
type: :development
|
50
|
-
prerelease: false
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - ">="
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: '0'
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: pry-byebug
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - ">="
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '0'
|
63
|
-
type: :development
|
64
|
-
prerelease: false
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
66
|
-
requirements:
|
67
|
-
- - ">="
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
70
28
|
- !ruby/object:Gem::Dependency
|
71
29
|
name: fuubar
|
72
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,16 +45,21 @@ dependencies:
|
|
87
45
|
requirements:
|
88
46
|
- - ">="
|
89
47
|
- !ruby/object:Gem::Version
|
90
|
-
version: 0
|
48
|
+
version: '0'
|
91
49
|
type: :development
|
92
50
|
prerelease: false
|
93
51
|
version_requirements: !ruby/object:Gem::Requirement
|
94
52
|
requirements:
|
95
53
|
- - ">="
|
96
54
|
- !ruby/object:Gem::Version
|
97
|
-
version: 0
|
98
|
-
description:
|
99
|
-
|
55
|
+
version: '0'
|
56
|
+
description: ' Ruby includes a huge amount of default awesomeness that tackles
|
57
|
+
most common development challenges. But every now and then, you find yourself performing
|
58
|
+
contortions to achieve results that, honestly, should feel more natural given the
|
59
|
+
language''s design elegance. Finishing Moves is a collection of methods designed
|
60
|
+
to assist in those "why is this awkward?" scenarios.
|
61
|
+
|
62
|
+
'
|
100
63
|
email:
|
101
64
|
- frank@forgecrafted.com
|
102
65
|
- chris@forgecrafted.com
|
@@ -148,15 +111,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
111
|
requirements:
|
149
112
|
- - ">="
|
150
113
|
- !ruby/object:Gem::Version
|
151
|
-
version: 2.
|
114
|
+
version: 2.7.0
|
152
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
116
|
requirements:
|
154
117
|
- - ">="
|
155
118
|
- !ruby/object:Gem::Version
|
156
119
|
version: '0'
|
157
120
|
requirements: []
|
158
|
-
|
159
|
-
rubygems_version: 2.4.5
|
121
|
+
rubygems_version: 3.3.7
|
160
122
|
signing_key:
|
161
123
|
specification_version: 4
|
162
124
|
summary: Small, focused, incredibly useful methods added to core Ruby classes.
|