finishing_moves 0.18 → 0.19

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
2
  SHA1:
3
- metadata.gz: ea386064f3ddd76587cfc19a0f3fa451bc5df6fe
4
- data.tar.gz: 68de87aee88555b846024b4edcbad5a6872c3f64
3
+ metadata.gz: 8d258c9fa2aa428c334917b3ed6f93e8e753cb22
4
+ data.tar.gz: 66b42d8c9755e15f7ccd6f0039b688b5a20fea87
5
5
  SHA512:
6
- metadata.gz: 2577531144756e18069014d715f319e3512e028840ae6a255de0bd0c51816c6714613cfaba67379c08316b36ec3d96266d8625473d2c2b6ebc7ecacbb3ae1ebb
7
- data.tar.gz: be79b56034b36aadb87fd36f1a35156134be6aef557d35a14c4d9f6f499d4fe4e9ba68977fe584754797bb73dff61b36bf3f4372d5bd033a576e2d42c9f4e13f
6
+ metadata.gz: 8dbc5e8995eef233120cf390d4671087d39c1752845c69b988f5354fbe06b2b2b3c0549bc40eb8a62715b3e841907fec01576e9277b9769db814c8a3a995b106
7
+ data.tar.gz: 4fe766497b240c4f6ad6793133c4bd7e87b32b0315f8978b368c1a511ca1de86a409f9a981ef47ce2bc12310eb7d3c06e7c62adc1861e336c31a9f87f462bc97
data/.travis.yml CHANGED
@@ -6,9 +6,8 @@ rvm:
6
6
  - 2.0.0
7
7
  - 2.1.0
8
8
  - 2.2.0
9
- - 2.2.1
10
- - 2.2.2
11
9
  - 2.3.0
10
+ - 2.4.0
12
11
  - ruby-head
13
12
 
14
13
  script: bundle exec rspec spec
@@ -14,7 +14,7 @@ class Array
14
14
 
15
15
  def to_indexed_hash(starting_key = 0)
16
16
  raise ArgumentError, "#{starting_key.inspect} is not an integer" unless starting_key.is_a? Integer
17
- to_hash_values(starting_key) { |i| i + 1 }
17
+ to_hash_values(starting_key)
18
18
  end
19
19
 
20
20
  def to_hash_keys(starting_value = 0, &block)
@@ -24,16 +24,4 @@ class Hash
24
24
  return self
25
25
  end
26
26
 
27
- # auto-nesting hashes
28
- # https://dzone.com/articles/create-nested-hashes-ruby
29
- # Goal:
30
- # a = {}
31
- # a[2][1] = 2
32
- # a[2][2][3] = 4
33
- # a[3][1][1][1] = 1
34
- def Hash.new_nested_hash
35
- Hash.new{ |h,k| h[k] = Hash.new(&h.default_proc) }
36
- end
37
-
38
-
39
27
  end
@@ -5,8 +5,7 @@ module Kernel
5
5
  result = yield
6
6
  return ret_val if result.nil?
7
7
  result
8
- rescue NoMethodError
9
- rescue NameError
8
+ rescue NoMethodError, NameError
10
9
  return ret_val
11
10
  end
12
11
  end
@@ -12,11 +12,7 @@ class Object
12
12
  alias_method :is_not_an?, :is_not_a?
13
13
 
14
14
  def same_as(compare)
15
- if compare.respond_to? :to_s
16
- self.to_s == compare.to_s
17
- else
18
- raise ArgumentError.new("Cannot compare \"#{self.class.name}\" to \"#{compare.class.name}\", no string conversion")
19
- end
15
+ self.to_s == compare.to_s
20
16
  end
21
17
  alias_method :same_as?, :same_as
22
18
 
@@ -26,10 +22,18 @@ class Object
26
22
  name.keyify
27
23
  end
28
24
 
25
+ def self.keyify!
26
+ name.keyify!
27
+ end
28
+
29
29
  def self.slugify
30
30
  name.slugify
31
31
  end
32
32
 
33
+ def self.slugify!
34
+ name.slugify!
35
+ end
36
+
33
37
  def false?
34
38
  return true if self.is_a? FalseClass
35
39
  return false
@@ -1,11 +1,5 @@
1
1
  class Symbol
2
2
 
3
- # TODO
4
- # Credit: http://thingsinabucket.com/2015/07/01/three_little_hacks/
5
- def ~@
6
- -> (o) { o.respond_to?(self) }
7
- end
8
-
9
3
  def keyify
10
4
  to_s.keyify
11
5
  end
@@ -14,4 +8,12 @@ class Symbol
14
8
  to_s.slugify
15
9
  end
16
10
 
11
+ def keyify!
12
+ to_s.keyify!
13
+ end
14
+
15
+ def slugify!
16
+ to_s.slugify!
17
+ end
18
+
17
19
  end
@@ -6,7 +6,7 @@ class String
6
6
  end
7
7
  end
8
8
 
9
- class Fixnum
9
+ class Integer
10
10
  def to_bool
11
11
  return true if self == 1
12
12
  return false if self == 0
@@ -1,3 +1,3 @@
1
1
  module FinishingMoves
2
- VERSION = "0.18"
2
+ VERSION = "0.19"
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.2.2'
6
+ DEFAULT_RUBY='2.4.1'
7
7
 
8
8
  ###############################################################################
9
9
  # Functions
data/spec/kernel_spec.rb CHANGED
@@ -24,6 +24,7 @@ describe Kernel do
24
24
  expect( nil_chain(false) { bogus_variable } ).to equal false
25
25
  expect( nil_chain('gotcha!') { bogus_variable } ).to eq 'gotcha!'
26
26
  expect( nil_chain('gotcha!') { params[:bogus_key] } ).to eq 'gotcha!'
27
+ expect( nil_chain('gotcha!') { raise NoMethodError } ).to eq 'gotcha!'
27
28
  expect( nil_chain('gotcha!') { params[:foo] } ).to eq 'bar'
28
29
 
29
30
  # alias
data/spec/numeric_spec.rb CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe "Numeric methods" do
4
4
 
5
- it "Fixnum#length" do
5
+ it "Integer#length" do
6
6
  expect(1.length).to eq 1
7
7
  expect(5.length).to eq 1
8
8
  expect(9.length).to eq 1
@@ -12,9 +12,6 @@ describe "Numeric methods" do
12
12
  expect(-9000.length).to eq 4
13
13
  # alias
14
14
  expect(-9000.digits).to eq 4
15
- end
16
-
17
- it "Bignum#length" do
18
15
  expect(12356469787881584554556.length).to eq 23
19
16
  expect(-12356469787881584554556.length).to eq 23
20
17
  # alias
@@ -40,7 +37,7 @@ describe "Numeric methods" do
40
37
  expect{ -0.9999999999999062.digits }.to raise_error(ArgumentError)
41
38
  end
42
39
 
43
- it "Fixnum#subtract_percent" do
40
+ it "Integer#subtract_percent" do
44
41
  expect(1.subtract_percent(10)).to eq 0.9
45
42
  expect(10.subtract_percent(10)).to eq 9.0
46
43
  expect(25.subtract_percent(5)).to eq 23.75
@@ -70,16 +67,13 @@ describe "Numeric methods" do
70
67
  end
71
68
 
72
69
 
73
- it "Fixnum#add_percent" do
70
+ it "Integer#add_percent" do
74
71
  expect(1.add_percent(10)).to eq 1.1
75
72
  expect(10.add_percent(10)).to eq 11.0
76
73
  expect(25.add_percent(5)).to eq 26.25
77
74
  expect(76.add_percent(40)).to eq 106.4
78
75
  expect(76.markup_by_percent(40)).to eq 106.4
79
76
  expect(200.markup_by_percent(100)).to eq 400
80
- end
81
-
82
- it "Bignum#add_percent" do
83
77
  expect(12356469787881584554556.add_percent(10)).to eq 1.3592116766669745e+22
84
78
  expect(12356469787881584554556.markup_by_percent(10)).to eq 1.3592116766669745e+22
85
79
  end
data/spec/object_spec.rb CHANGED
@@ -105,5 +105,9 @@ describe Object do
105
105
  expect{ :symbol.false_? }.to raise_error(RuntimeError)
106
106
  end
107
107
 
108
+ end
109
+
110
+ #############################
108
111
 
112
+ class NoStringObject
109
113
  end
data/spec/string_spec.rb CHANGED
@@ -154,36 +154,57 @@ describe String do
154
154
  expect("\n\n".newline_to(0)).to eq '00'
155
155
  expect("\n\n".newline_to(true)).to eq 'truetrue'
156
156
 
157
+ # should return a modified object, leaving original intact
158
+ newline = "\n"
159
+ bar = newline.newline_to(:bar)
160
+ expect(newline).to eq "\n"
161
+ expect(bar).to eq 'bar'
162
+
157
163
  expect("Let's play Global Thermonuclear War.\n\r".newline_to).to eq "Let's play Global Thermonuclear War. "
158
164
  expect("A strange game.\n\nThe only winning move is not to play.\r\nHow about a nice game of chess?\r".newline_to).
159
165
  to eq "A strange game. The only winning move is not to play. How about a nice game of chess? "
160
166
  end
161
167
 
168
+ it "#newline_to!" do
169
+ var = "\n"
170
+ var.newline_to! :foo
171
+ expect(var).to eq 'foo'
172
+ end
173
+
174
+ keyify_sets = [
175
+ [Integer, :integer],
176
+ [Math::DomainError, :math_domain_error],
177
+ ['FooBarBaz', :foo_bar_baz],
178
+ [:FooBarBaz, :foo_bar_baz],
179
+ ["Foo-Bar'Baz", :foo_bar_baz],
180
+ ['(Foo*&Bar!Baz?', :foo_bar_baz],
181
+ ['1234FooBAR', :foo_bar],
182
+ ['!@#$Foo0987', :foo0987],
183
+ ["Bill O'Shea", :bill_o_shea],
184
+ ["Bill O Shea", :bill_o_shea],
185
+ ["Bill O Shea", :bill_o_shea],
186
+ ]
187
+
162
188
  it '#keyify' do
163
- expect(Integer.keyify).to eq :integer
164
- expect(Math::DomainError.keyify).to eq :math_domain_error
165
- expect('FooBarBaz'.keyify).to eq :foo_bar_baz
166
- expect(:FooBarBaz.keyify).to eq :foo_bar_baz
167
- expect("Foo-Bar'Baz".keyify).to eq :foo_bar_baz
168
- expect('(Foo*&Bar!Baz?'.keyify).to eq :foo_bar_baz
169
- expect('1234FooBAR'.keyify).to eq :foo_bar
170
- expect('!@#$Foo0987'.keyify).to eq :foo0987
189
+ keyify_sets.each do |set|
190
+ inc, out = set
191
+ expect(inc.keyify).to eq out
192
+ end
171
193
  expect('!@#$%^'.keyify).to eq nil
172
194
  expect('12345678'.keyify).to eq nil
173
- expect("Bill O'Shea".keyify).to eq :bill_o_shea
174
- expect("Bill O Shea".keyify).to eq :bill_o_shea
175
- expect("Bill O Shea".keyify).to eq :bill_o_shea
176
-
177
195
  # make sure we're not performing in place
178
196
  str = 'FooBarBaz'
179
197
  expect(str.keyify).to eq :foo_bar_baz
180
198
  expect(str).to eq 'FooBarBaz'
181
-
182
199
  # should work on frozen values
183
200
  expect('FooBarBaz'.freeze.keyify).to eq :foo_bar_baz
184
201
  end
185
202
 
186
203
  it '#keyify!' do
204
+ keyify_sets.each do |set|
205
+ inc, out = set
206
+ expect(inc.keyify!).to eq out
207
+ end
187
208
  expect{ '!@#$%^'.keyify! }.to raise_error(ArgumentError)
188
209
  expect{ '12345678'.keyify! }.to raise_error(ArgumentError)
189
210
  end
@@ -193,19 +214,25 @@ describe String do
193
214
  expect('1 2 3 4 5'.dedupe(' ').replace_whitespace('+')).to eq '1+2+3+4+5'
194
215
  end
195
216
 
217
+ slugify_sets = [
218
+ [Integer, 'integer'],
219
+ [Math::DomainError, 'math-domain-error'],
220
+ ['FooBarBaz', 'foo-bar-baz'],
221
+ [:FooBarBaz, 'foo-bar-baz'],
222
+ ["Foo-Bar'Baz", 'foo-bar-baz'],
223
+ ['(Foo*&Bar!Baz?', 'foo-bar-baz'],
224
+ ["Bill O'Shea", 'bill-o-shea'],
225
+ ["Bill O Shea", 'bill-o-shea'],
226
+ ["Bill O Shea", 'bill-o-shea'],
227
+ ]
228
+
196
229
  it '#slugify' do
197
- expect(Integer.slugify).to eq 'integer'
198
- expect(Math::DomainError.slugify).to eq 'math-domain-error'
199
- expect('FooBarBaz'.slugify).to eq 'foo-bar-baz'
200
- expect(:FooBarBaz.slugify).to eq 'foo-bar-baz'
201
- expect("Foo-Bar'Baz".slugify).to eq 'foo-bar-baz'
202
- expect('(Foo*&Bar!Baz?'.slugify).to eq 'foo-bar-baz'
230
+ slugify_sets.each do |set|
231
+ inc, out = set
232
+ expect(inc.slugify).to eq out
233
+ end
203
234
  expect('!@#$Foo0987'.slugify).to eq 'foo0987'
204
235
  expect('!@#$%^'.slugify).to eq nil
205
- expect("Bill O'Shea".slugify).to eq 'bill-o-shea'
206
- expect("Bill O Shea".slugify).to eq 'bill-o-shea'
207
- expect("Bill O Shea".slugify).to eq 'bill-o-shea'
208
-
209
236
  # make sure we're not performing in place
210
237
  str = 'FooBarBaz'
211
238
  expect(str.slugify).to eq 'foo-bar-baz'
@@ -221,6 +248,10 @@ describe String do
221
248
  end
222
249
 
223
250
  it '#slugify!' do
251
+ slugify_sets.each do |set|
252
+ inc, out = set
253
+ expect(inc.slugify!).to eq out
254
+ end
224
255
  expect{ '!@#$%^'.slugify! }.to raise_error(ArgumentError)
225
256
  expect{ '12345678'.slugify! }.not_to raise_error
226
257
  end
data/spec/to_bool_spec.rb CHANGED
@@ -20,7 +20,7 @@ describe "Boolean typecasting" do
20
20
  expect{ "000".to_bool }.to raise_error(ArgumentError)
21
21
  end
22
22
 
23
- it "Fixnum#to_bool" do
23
+ it "Integer#to_bool" do
24
24
  expect(1.to_bool).to eq true
25
25
  expect(0.to_bool).to eq false
26
26
  expect{ 2.to_bool }.to raise_error(ArgumentError)
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: '0.18'
4
+ version: '0.19'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Koehl
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-03-22 00:00:00.000000000 Z
12
+ date: 2017-06-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rb-readline
@@ -135,7 +135,6 @@ files:
135
135
  - spec/object_spec.rb
136
136
  - spec/spec_helper.rb
137
137
  - spec/string_spec.rb
138
- - spec/symbol_spec.rb
139
138
  - spec/to_bool_spec.rb
140
139
  homepage: https://github.com/forgecrafted/finishing_moves
141
140
  licenses:
@@ -171,5 +170,4 @@ test_files:
171
170
  - spec/object_spec.rb
172
171
  - spec/spec_helper.rb
173
172
  - spec/string_spec.rb
174
- - spec/symbol_spec.rb
175
173
  - spec/to_bool_spec.rb
data/spec/symbol_spec.rb DELETED
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Symbol do
4
-
5
- it "unary respond_to" do
6
- a_thing = TestThing.new 'foo bar'
7
- expect(a_thing).to eq 'foo bar'
8
- end
9
-
10
- end
11
-
12
-
13
- class TestThing < String
14
-
15
- def custom_method
16
- 'it works!'
17
- end
18
-
19
- end