finishing_moves 1.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d37ca4693b6a2a3120e8ee286ab7d201e489473b
4
- data.tar.gz: 71f81d5815febb3bd3944fbd74c8ba374afd37bd
2
+ SHA256:
3
+ metadata.gz: 55befc1e2e32958cf79f502b505192043bc6250f0dca0c1149ab1592c09b4858
4
+ data.tar.gz: e1bbf88d19b9534f0ec67cdd68ef0f405f8668498f0997aa8dc7a1c1d17769e8
5
5
  SHA512:
6
- metadata.gz: e0cdbe53527bf2fb84106d50768ef3c28e630b81ba28bdb58f1f8aaa3cda1e5792165e95127b4ceda23a49119ba8f0116369ee16a1b9d69fc750d0a294d2f93a
7
- data.tar.gz: b6afe08d894be6a022974b0859bd36d41d5de628e62be9c0df015f90e10c804d2df93fba445c06445251c015aa6d5738dfd53505cf56ffefbd4ebb8c1e7c8d48
6
+ metadata.gz: 5e0aaf8177aff25d04ee76ca9c09351c6f3a999827fed2ea4abb5c6c76fab3b3f236b58797d20c563083ab11d4b852dfd80b996173bb488a688a0550995943c5
7
+ data.tar.gz: b277786b540bd97e1651f4469608a924c35a35579ccd0e7da173d11c8d39628172899223d808cd353dcb90c39b9969b0f95abd53972875fc733e462691717c03
data/.travis.yml CHANGED
@@ -3,12 +3,11 @@ language: ruby
3
3
  cache: bundler
4
4
 
5
5
  rvm:
6
- - 2.0.0
7
- - 2.1.0
8
- - 2.2.0
9
- - 2.3.0
10
- - 2.4.0
11
- - 2.5.0
6
+ - 2.7.6
7
+ - 3.0.4
8
+ - 3.1.0
9
+ - 3.1.1
10
+ - 3.1.2
12
11
  - ruby-head
13
12
 
14
13
  script: bundle exec rspec spec
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Finishing Moves
2
2
  [![Gem Version](https://badge.fury.io/rb/finishing_moves.svg)](https://rubygems.org/gems/finishing_moves)
3
- [![Build Status](https://travis-ci.org/BattleBrisket/rails-force-reload.svg?branch=master)](https://travis-ci.org/BattleBrisket/rails-force-reload)
3
+ [![Build Status](https://travis-ci.org/forgecrafted/finishing_moves.svg?branch=master)](https://travis-ci.org/forgecrafted/finishing_moves)
4
+ [![Mentioned in Awesome Ruby](https://awesome.re/mentioned-badge.svg)](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`](https://github.com/forgecrafted/finishing_moves/wiki/Array#arrayto_sym)
29
- - [`Array#to_sym_soft`](https://github.com/forgecrafted/finishing_moves/wiki/Array#arrayto_sym_soft)
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
- *Multi-class enhancement*
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.0.0` and above**. Probably works in `1.9.3`.
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/trusty64"
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", 4,
21
+ "--cpus", 2,
22
22
  "--ioapic", "on",
23
23
  # Enable native host virtualization features (yields better performance).
24
24
  "--pae", "on",
@@ -7,25 +7,22 @@ Gem::Specification.new do |s|
7
7
  s.name = "finishing_moves"
8
8
  s.version = FinishingMoves::VERSION
9
9
  s.platform = Gem::Platform::RUBY
10
- s.authors = ["Frank Koehl", "Chris Tonkinson"]
11
- s.email = ["frank@forgecrafted.com", "chris@forgecrafted.com"]
10
+ s.authors = ["Frank Koehl"]
11
+ s.email = ["frank@forgecrafted.com"]
12
12
  s.summary = %q{Small, focused, incredibly useful methods added to core Ruby classes.}
13
13
  s.description = <<-EOF
14
14
  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.
15
15
  EOF
16
- s.homepage = "https://github.com/forgecrafted/finishing_moves"
16
+ s.homepage = "https://github.com/battlebrisket/finishing_moves"
17
17
  s.license = "MIT"
18
18
 
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.8.0'
24
+ s.add_development_dependency 'coveralls', '>= 0'
28
25
 
29
- s.required_ruby_version = '>= 2.0.0'
26
+ s.required_ruby_version = '>= 2.7.0'
30
27
 
31
28
  end
@@ -27,29 +27,25 @@ class Array
27
27
  end
28
28
  alias_method :to_hash_as_keys, :to_hash_keys
29
29
 
30
- def to_sym
30
+ def to_sym_strict
31
31
  map { |x| x.to_sym }
32
32
  end
33
- alias_method :to_sym_hard, :to_sym
34
33
 
35
- def to_sym!
34
+ def to_sym_strict!
36
35
  map! { |x| x.to_sym }
37
36
  end
38
- alias_method :to_sym_hard!, :to_sym!
39
37
 
40
- def to_sym_soft
38
+ def to_sym_loose
41
39
  map do |x|
42
- begin
40
+ if x.respond_to?(:to_sym)
43
41
  x.to_sym
44
- rescue NoMethodError => e
42
+ else
45
43
  x
46
- rescue Exception
47
- raise
48
44
  end
49
45
  end
50
46
  end
51
47
 
52
- def to_sym_soft!
48
+ def to_sym_loose!
53
49
  map! do |x|
54
50
  begin
55
51
  x.to_sym
@@ -24,4 +24,11 @@ class Hash
24
24
  return self
25
25
  end
26
26
 
27
+ # TODO
28
+ # Replicate `sample` method functionality from Array
29
+ def sample
30
+ key = self.keys.sample
31
+ return {:"#{key}" => self[key]}
32
+ end
33
+
27
34
  end
@@ -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?
@@ -1,3 +1,3 @@
1
1
  module FinishingMoves
2
- VERSION = "1.0"
2
+ VERSION = "1.2.1"
3
3
  end
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='2.4.1'
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
- python-software-properties \
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/array_spec.rb CHANGED
@@ -99,45 +99,29 @@ describe Array do
99
99
  end
100
100
  end
101
101
 
102
- it '#to_sym' do
102
+ it '#to_sym_strict' do
103
103
  test = ['FOO', 'bar', :baz]
104
- expect(test.to_sym).to eq [:FOO, :bar, :baz]
104
+ expect(test.to_sym_strict).to eq [:FOO, :bar, :baz]
105
105
  expect(test).to eq ['FOO', 'bar', :baz]
106
- expect{ [1].to_sym }.to raise_error NoMethodError
107
- # FinishingMoves::FalseClass#to_sym
108
- expect([false].to_sym).to eq [:false]
106
+ expect{ [1].to_sym_strict }.to raise_error NoMethodError
109
107
  end
110
108
 
111
- it '#to_sym!' do
109
+ it '#to_sym_strict!' do
112
110
  test = ['FOO', 'bar', :baz]
113
- expect(test.to_sym!).to eq [:FOO, :bar, :baz]
111
+ expect(test.to_sym_strict!).to eq [:FOO, :bar, :baz]
114
112
  expect(test).to eq [:FOO, :bar, :baz]
115
- expect{ [1].to_sym! }.to raise_error NoMethodError
113
+ expect{ [1].to_sym_strict! }.to raise_error NoMethodError
116
114
  end
117
115
 
118
- it '#to_sym_hard' do
119
- test = ['FOO', 'bar', :baz]
120
- expect(test.to_sym_hard).to eq [:FOO, :bar, :baz]
121
- expect(test).to eq ['FOO', 'bar', :baz]
122
- expect{ [1].to_sym_hard }.to raise_error NoMethodError
123
- end
124
-
125
- it '#to_sym_hard!' do
126
- test = ['FOO', 'bar', :baz]
127
- expect(test.to_sym_hard!).to eq [:FOO, :bar, :baz]
128
- expect(test).to eq [:FOO, :bar, :baz]
129
- expect{ [1].to_sym_hard! }.to raise_error NoMethodError
130
- end
131
-
132
- it '#to_sym_soft' do
116
+ it '#to_sym_loose' do
133
117
  test = ['FOO', 'bar', :baz, 1, {bat: 'bat'}, /hay/]
134
- expect(test.to_sym_soft).to eq [:FOO, :bar, :baz, 1, {bat: 'bat'}, /hay/]
118
+ expect(test.to_sym_loose).to eq [:FOO, :bar, :baz, 1, {bat: 'bat'}, /hay/]
135
119
  expect(test).to eq ['FOO', 'bar', :baz, 1, {bat: 'bat'}, /hay/]
136
120
  end
137
121
 
138
- it '#to_sym_soft!' do
122
+ it '#to_sym_loose!' do
139
123
  test = ['FOO', 'bar', :baz, 1, {bat: 'bat'}, /hay/]
140
- expect(test.to_sym_soft!).to eq [:FOO, :bar, :baz, 1, {bat: 'bat'}, /hay/]
124
+ expect(test.to_sym_loose!).to eq [:FOO, :bar, :baz, 1, {bat: 'bat'}, /hay/]
141
125
  expect(test).to eq [:FOO, :bar, :baz, 1, {bat: 'bat'}, /hay/]
142
126
  end
143
127
 
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
@@ -3,10 +3,6 @@ require 'rubygems'
3
3
  require 'bundler/setup'
4
4
  Bundler.setup
5
5
 
6
- require 'priscilla'
7
- require 'pry'
8
- require 'byebug'
9
-
10
6
  require 'coveralls'
11
7
  Coveralls.wear!
12
8
 
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,30 +1,15 @@
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Koehl
8
- - Chris Tonkinson
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2018-08-09 00:00:00.000000000 Z
11
+ date: 2022-08-30 00:00:00.000000000 Z
13
12
  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
13
  - !ruby/object:Gem::Dependency
29
14
  name: rspec
30
15
  requirement: !ruby/object:Gem::Requirement
@@ -39,34 +24,6 @@ dependencies:
39
24
  - - "~>"
40
25
  - !ruby/object:Gem::Version
41
26
  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
27
  - !ruby/object:Gem::Dependency
71
28
  name: fuubar
72
29
  requirement: !ruby/object:Gem::Requirement
@@ -87,19 +44,23 @@ dependencies:
87
44
  requirements:
88
45
  - - ">="
89
46
  - !ruby/object:Gem::Version
90
- version: 0.8.0
47
+ version: '0'
91
48
  type: :development
92
49
  prerelease: false
93
50
  version_requirements: !ruby/object:Gem::Requirement
94
51
  requirements:
95
52
  - - ">="
96
53
  - !ruby/object:Gem::Version
97
- version: 0.8.0
98
- description: |2
99
- 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.
54
+ version: '0'
55
+ description: ' Ruby includes a huge amount of default awesomeness that tackles
56
+ most common development challenges. But every now and then, you find yourself performing
57
+ contortions to achieve results that, honestly, should feel more natural given the
58
+ language''s design elegance. Finishing Moves is a collection of methods designed
59
+ to assist in those "why is this awkward?" scenarios.
60
+
61
+ '
100
62
  email:
101
63
  - frank@forgecrafted.com
102
- - chris@forgecrafted.com
103
64
  executables: []
104
65
  extensions: []
105
66
  extra_rdoc_files: []
@@ -136,7 +97,7 @@ files:
136
97
  - spec/spec_helper.rb
137
98
  - spec/string_spec.rb
138
99
  - spec/to_bool_spec.rb
139
- homepage: https://github.com/forgecrafted/finishing_moves
100
+ homepage: https://github.com/battlebrisket/finishing_moves
140
101
  licenses:
141
102
  - MIT
142
103
  metadata: {}
@@ -148,15 +109,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
109
  requirements:
149
110
  - - ">="
150
111
  - !ruby/object:Gem::Version
151
- version: 2.0.0
112
+ version: 2.7.0
152
113
  required_rubygems_version: !ruby/object:Gem::Requirement
153
114
  requirements:
154
115
  - - ">="
155
116
  - !ruby/object:Gem::Version
156
117
  version: '0'
157
118
  requirements: []
158
- rubyforge_project:
159
- rubygems_version: 2.4.5
119
+ rubygems_version: 3.3.7
160
120
  signing_key:
161
121
  specification_version: 4
162
122
  summary: Small, focused, incredibly useful methods added to core Ruby classes.