finishing_moves 0.2.0 → 0.3.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 +4 -4
- data/.gitignore +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +12 -0
- data/Gemfile.lock +58 -58
- data/LICENSE +1 -1
- data/README.md +659 -110
- data/Rakefile +10 -0
- data/finishing_moves.gemspec +15 -0
- data/lib/finishing_moves/array.rb +30 -0
- data/lib/finishing_moves/date_and_time.rb +25 -0
- data/lib/finishing_moves/enumerable.rb +18 -0
- data/lib/finishing_moves/fixnum.rb +4 -7
- data/lib/finishing_moves/kernel.rb +35 -0
- data/lib/finishing_moves/object.rb +7 -30
- data/lib/finishing_moves/string.rb +127 -0
- data/lib/finishing_moves/version.rb +1 -1
- data/provision.sh +1 -2
- data/spec/array_spec.rb +127 -0
- data/spec/enumerable_spec.rb +37 -0
- data/spec/fixnum_spec.rb +8 -0
- data/spec/kernel_spec.rb +117 -0
- data/spec/object_spec.rb +1 -103
- data/spec/spec_helper.rb +5 -0
- data/spec/string_spec.rb +159 -0
- metadata +30 -3
data/spec/object_spec.rb
CHANGED
@@ -2,54 +2,6 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Object do
|
4
4
|
|
5
|
-
it "#nil_chain" do
|
6
|
-
expect(nil_chain{bogus_variable}).to eq nil
|
7
|
-
expect(nil_chain{bogus_hash[:foo]}).to eq nil
|
8
|
-
params = { :foo => 'bar' }
|
9
|
-
expect(nil_chain{ params[:bogus_key] }).to eq nil
|
10
|
-
expect(nil_chain{ params[:foo] }).to eq 'bar'
|
11
|
-
var = 'a simple string'
|
12
|
-
expect(nil_chain{ var.transmogrify }).to eq nil
|
13
|
-
|
14
|
-
c = C.new
|
15
|
-
b = B.new c
|
16
|
-
a = A.new b
|
17
|
-
expect(a.b.c.hello).to eq "Hello, world!"
|
18
|
-
b.c = nil
|
19
|
-
expect(nil_chain{a.b.c.hello}).to eq nil
|
20
|
-
a = nil
|
21
|
-
expect(nil_chain{a.b.c.hello}).to eq nil
|
22
|
-
|
23
|
-
expect( nil_chain(true) { bogus_variable } ).to equal true
|
24
|
-
expect( nil_chain(false) { bogus_variable } ).to equal false
|
25
|
-
expect( nil_chain('gotcha!') { bogus_variable } ).to eq 'gotcha!'
|
26
|
-
expect( nil_chain('gotcha!') { params[:bogus_key] } ).to eq 'gotcha!'
|
27
|
-
expect( nil_chain('gotcha!') { params[:foo] } ).to eq 'bar'
|
28
|
-
|
29
|
-
# alias
|
30
|
-
expect(method_chain{bogus_variable}).to eq nil
|
31
|
-
end
|
32
|
-
|
33
|
-
it "#bool_chain" do
|
34
|
-
expect(bool_chain{bogus_variable}).to equal false
|
35
|
-
var = true
|
36
|
-
expect(bool_chain{var}).to equal true
|
37
|
-
var = 'foo'
|
38
|
-
expect(bool_chain{var}).to eq 'foo'
|
39
|
-
result = bool_chain{ var.transmogrify }
|
40
|
-
expect(result).to equal false
|
41
|
-
end
|
42
|
-
|
43
|
-
it "#class_exists?" do
|
44
|
-
expect(class_exists? :Symbol).to eq true
|
45
|
-
expect(class_exists? :Symbology).to eq false
|
46
|
-
expect(class_exists? 'Symbol').to eq true
|
47
|
-
expect(class_exists? 'Symbology').to eq false
|
48
|
-
expect(class_exists? :Array).to eq true
|
49
|
-
expect(class_exists? :aRRay).to eq false
|
50
|
-
expect(class_exists? :ARRAY).to eq false
|
51
|
-
end
|
52
|
-
|
53
5
|
it "#not_nil?" do
|
54
6
|
var = nil
|
55
7
|
expect(var.not_nil?).to eq false
|
@@ -71,61 +23,7 @@ describe Object do
|
|
71
23
|
expect(user.same_as(:FACELESS_ONE)).to eq false
|
72
24
|
end
|
73
25
|
|
74
|
-
it "#
|
75
|
-
expect(test_cascade).to be_nil
|
76
|
-
expect(test_cascade('step1')).to eq 1
|
77
|
-
expect(test_cascade('step2')).to eq 2
|
78
|
-
expect(test_cascade('step3')).to eq 3
|
79
|
-
expect(test_cascade('foobar')).to eq 4
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
# some small test fixtures
|
85
|
-
|
86
|
-
class A
|
87
|
-
attr_accessor :b
|
88
|
-
def initialize(b)
|
89
|
-
@b = b
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
class B
|
94
|
-
attr_accessor :c
|
95
|
-
def initialize(c)
|
96
|
-
@c = c
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
class C
|
101
|
-
def hello
|
102
|
-
"Hello, world!"
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
class User
|
107
|
-
attr_writer :handle
|
108
|
-
|
109
|
-
def handle
|
110
|
-
@handle || "faceless_one"
|
26
|
+
it "#is_an?" do
|
111
27
|
end
|
112
28
|
|
113
|
-
def to_s
|
114
|
-
handle.to_s
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_cascade(trigger = nil)
|
119
|
-
ultimate_value = nil
|
120
|
-
cascade do
|
121
|
-
break if trigger.nil?
|
122
|
-
ultimate_value = 1
|
123
|
-
break if trigger == 'step1'
|
124
|
-
ultimate_value = 2
|
125
|
-
break if trigger == 'step2'
|
126
|
-
ultimate_value = 3
|
127
|
-
break if trigger == 'step3'
|
128
|
-
ultimate_value = 4
|
129
|
-
end
|
130
|
-
return ultimate_value
|
131
29
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -48,6 +48,11 @@ RSpec.configure do |config|
|
|
48
48
|
mocks.verify_partial_doubles = true
|
49
49
|
end
|
50
50
|
|
51
|
+
config.filter_run :focus
|
52
|
+
config.run_all_when_everything_filtered = true
|
53
|
+
|
54
|
+
config.order = :random
|
55
|
+
|
51
56
|
# The settings below are suggested to provide a good initial experience
|
52
57
|
# with RSpec, but feel free to customize to your heart's content.
|
53
58
|
=begin
|
data/spec/string_spec.rb
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe String do
|
4
|
+
|
5
|
+
it '#dedupe' do
|
6
|
+
expect('___foo___'.dedupe('_')).to eq '_foo_'
|
7
|
+
expect('---foo---'.dedupe('-')).to eq '-foo-'
|
8
|
+
expect('___foo---'.dedupe('_-')).to eq '_foo-'
|
9
|
+
expect('___foo__bar_baz--bing'.dedupe('_')).to eq '_foo_bar_baz--bing'
|
10
|
+
expect('foo'.dedupe('o')).to eq 'fo'
|
11
|
+
expect('foo'.dedupe('O')).to eq 'foo'
|
12
|
+
expect('[[foo]]]'.dedupe('[]')).to eq '[foo]'
|
13
|
+
expect('/crazy//concatenated////file/path'.dedupe('/')).to eq '/crazy/concatenated/file/path'
|
14
|
+
|
15
|
+
# make sure our use of gsub! isn't screwing us over
|
16
|
+
orig = '___foo___'
|
17
|
+
modified = orig.dedupe('_')
|
18
|
+
expect(modified).to eq '_foo_'
|
19
|
+
expect(orig).to eq '___foo___'
|
20
|
+
end
|
21
|
+
|
22
|
+
it '#dedupe!' do
|
23
|
+
str = '___foo___'
|
24
|
+
str.dedupe!('_')
|
25
|
+
expect(str).to eq '_foo_'
|
26
|
+
end
|
27
|
+
|
28
|
+
it '#strip_all (incl _strip_all_prep)' do
|
29
|
+
expect('___foo___'.strip_all).to eq 'foo'
|
30
|
+
expect('---foo---'.strip_all).to eq 'foo'
|
31
|
+
expect('-_-foo-_-'.strip_all).to eq 'foo'
|
32
|
+
expect('_-_8-foo-8_-_'.strip_all).to eq '8-foo-8'
|
33
|
+
expect('0123456789-foo-9876543210'.strip_all('0-9')).to eq '-foo-'
|
34
|
+
expect('0123-foo-3210'.strip_all('0-9-')).to eq 'foo'
|
35
|
+
expect('0123-foo-3210'.strip_all('a-z')).to eq '0123-foo-3210'
|
36
|
+
expect('foo-314-foo'.strip_all('a-z')).to eq '-314-'
|
37
|
+
expect('foo-314-foo'.strip_all('a-z-')).to eq '314'
|
38
|
+
expect('foo-314-foo'.strip_all('A-Z')).to eq 'foo-314-foo'
|
39
|
+
expect('FOO-314-FOO'.strip_all('A-Z')).to eq '-314-'
|
40
|
+
expect('FOO 314 FOO'.strip_all('A-Z')).to eq '314'
|
41
|
+
|
42
|
+
expect('abcdefghijklmnopqrstuvwxyz'.strip_all('a-z')).to eq ''
|
43
|
+
expect('ABCDEFGHIJKLMNOPQRSTUVWXYZ'.strip_all('A-Z')).to eq ''
|
44
|
+
expect('ABCDEFGHIJKLM FOO NOPQRSTUVWXYZ'.strip_all('A-Z')).to eq ''
|
45
|
+
|
46
|
+
expect('000000'.strip_all('0')).to eq ''
|
47
|
+
expect('[[000]]'.strip_all('[0]')).to eq ''
|
48
|
+
expect('. $ ^ { [ ( | ) * + ? \ '.strip_all('. $ ^ { [ ( | ) * + ? \ ')).to eq ''
|
49
|
+
expect('/[a|valid|regex]+/'.strip_all('/[]+')).to eq 'a|valid|regex'
|
50
|
+
|
51
|
+
expect('_1 0__spaces_incl__0 1_'.strip_all('0-9_')).to eq 'spaces_incl'
|
52
|
+
expect(' _spaces_incl_ '.strip_all).to eq 'spaces_incl'
|
53
|
+
|
54
|
+
expect("__'''foo__'".strip_all('_\'') ).to eq 'foo'
|
55
|
+
expect('abcdefghijklm foo123 nopqrstuvwxyz'.strip_all('a-z0-9')).to eq ''
|
56
|
+
expect('hello world'.strip_all('a-z')).to eq ''
|
57
|
+
|
58
|
+
expect{'bad call'.strip_all(101)}.to raise_error(ArgumentError)
|
59
|
+
end
|
60
|
+
|
61
|
+
it '#strip_all!' do
|
62
|
+
str = '___foo___'
|
63
|
+
str.strip_all!
|
64
|
+
expect(str).to eq 'foo'
|
65
|
+
end
|
66
|
+
|
67
|
+
it '#lstrip_all' do
|
68
|
+
expect('___foo___'.lstrip_all).to eq 'foo___'
|
69
|
+
end
|
70
|
+
|
71
|
+
it '#lstrip_all!' do
|
72
|
+
str = '___foo___'
|
73
|
+
str.lstrip_all!
|
74
|
+
expect(str).to eq 'foo___'
|
75
|
+
end
|
76
|
+
|
77
|
+
it '#rstrip_all' do
|
78
|
+
expect('___foo___'.rstrip_all).to eq '___foo'
|
79
|
+
end
|
80
|
+
|
81
|
+
it '#rstrip_all!' do
|
82
|
+
str = '___foo___'
|
83
|
+
str.rstrip_all!
|
84
|
+
expect(str).to eq '___foo'
|
85
|
+
end
|
86
|
+
|
87
|
+
it '#match?' do
|
88
|
+
expect('hello'.match?('he')).to be true
|
89
|
+
expect('hello'.match?('he', 1)).to be false
|
90
|
+
expect('hello'.match?('o')).to be true
|
91
|
+
expect('hello'.match?('ol')).to be false
|
92
|
+
expect('hello'.match?('(.)')).to be true
|
93
|
+
expect('hello'.match?(/(.)/)).to be true
|
94
|
+
expect('hello'.match?('xx')).to be false
|
95
|
+
end
|
96
|
+
|
97
|
+
it '#remove_whitespace' do
|
98
|
+
expect(' a b c d e'.remove_whitespace).to eq 'abcde'
|
99
|
+
expect(' [ foo ] '.remove_whitespace).to eq '[foo]'
|
100
|
+
expect(' '.remove_whitespace).to eq ''
|
101
|
+
expect('. $ ^ { [ ( | ) * + ? \ '.remove_whitespace).to eq '.$^{[(|)*+?\\'
|
102
|
+
expect('a b c d e'.remove_whitespace('+')).to eq 'a+b+c+d+e'
|
103
|
+
expect('a b c d e'.remove_whitespace('+')).to eq 'a++b+c+d+e'
|
104
|
+
expect('a b c d e'.remove_whitespace('__')).to eq 'a__b__c__d__e'
|
105
|
+
end
|
106
|
+
|
107
|
+
it '#remove_whitespace!' do
|
108
|
+
str = ' a b c d e'
|
109
|
+
str.remove_whitespace!
|
110
|
+
expect(str).to eq 'abcde'
|
111
|
+
end
|
112
|
+
|
113
|
+
it '#nl2br' do
|
114
|
+
expect("\n".nl2br).to eq "<br />\n"
|
115
|
+
expect("\n\r".nl2br).to eq "<br />\n"
|
116
|
+
expect("\r\n".nl2br).to eq "<br />\n"
|
117
|
+
expect("\n\r\n".nl2br).to eq "<br />\n<br />\n"
|
118
|
+
expect("\r\n\r\n".nl2br).to eq "<br />\n<br />\n"
|
119
|
+
expect("\r\r\n".nl2br).to eq "<br />\n<br />\n"
|
120
|
+
expect("\r\r".nl2br).to eq "<br />\n<br />\n"
|
121
|
+
expect("\n\r\r".nl2br).to eq "<br />\n<br />\n"
|
122
|
+
|
123
|
+
expect("Let's play Global Thermonuclear War.\n\r".nl2br).to eq "Let's play Global Thermonuclear War.<br />\n"
|
124
|
+
expect("A strange game.\n\nThe only winning move is not to play.\r\nHow about a nice game of chess?\r".nl2br).
|
125
|
+
to eq "A strange game.<br />\n<br />\nThe only winning move is not to play.<br />\nHow about a nice game of chess?<br />\n"
|
126
|
+
end
|
127
|
+
|
128
|
+
it '#keyify' do
|
129
|
+
expect(SizedQueue.keyify).to eq :thread_sized_queue
|
130
|
+
expect(Integer.keyify).to eq :integer
|
131
|
+
expect(Math::DomainError.keyify).to eq :math_domain_error
|
132
|
+
expect('FooBarBaz'.keyify).to eq :foo_bar_baz
|
133
|
+
expect(:FooBarBaz.keyify).to eq :foo_bar_baz
|
134
|
+
expect("Foo-Bar'Baz".keyify).to eq :foo_bar_baz
|
135
|
+
expect('(Foo*&Bar!Baz?'.keyify).to eq :foo_bar_baz
|
136
|
+
expect('1234FooBAR'.keyify).to eq :foo_bar
|
137
|
+
expect('!@#$Foo0987'.keyify).to eq :foo0987
|
138
|
+
expect('!@#$%^'.keyify).to eq nil
|
139
|
+
expect('12345678'.keyify).to eq nil
|
140
|
+
expect("Bill O'Shea".keyify).to eq :bill_o_shea
|
141
|
+
expect("Bill O Shea".keyify).to eq :bill_o_shea
|
142
|
+
expect("Bill O Shea".keyify).to eq :bill_o_shea
|
143
|
+
|
144
|
+
# make sure we're not performing in place
|
145
|
+
str = 'FooBarBaz'
|
146
|
+
expect(str.keyify).to eq :foo_bar_baz
|
147
|
+
expect(str).to eq 'FooBarBaz'
|
148
|
+
end
|
149
|
+
|
150
|
+
it '#keyify!' do
|
151
|
+
expect{ '!@#$%^'.keyify! }.to raise_error(ArgumentError)
|
152
|
+
expect{ '12345678'.keyify! }.to raise_error(ArgumentError)
|
153
|
+
end
|
154
|
+
|
155
|
+
it "dedupe + remove_whitespace" do
|
156
|
+
expect('1 2 3 4 5'.dedupe(' ').remove_whitespace('+')).to eq '1+2+3+4+5'
|
157
|
+
end
|
158
|
+
|
159
|
+
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: 0.
|
4
|
+
version: 0.3.0
|
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: 2015-01-
|
12
|
+
date: 2015-01-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rb-readline
|
@@ -92,29 +92,52 @@ extra_rdoc_files: []
|
|
92
92
|
files:
|
93
93
|
- ".gitignore"
|
94
94
|
- ".rspec"
|
95
|
+
- ".ruby-version"
|
96
|
+
- ".travis.yml"
|
95
97
|
- Gemfile
|
96
98
|
- Gemfile.lock
|
97
99
|
- LICENSE
|
98
100
|
- README.md
|
101
|
+
- Rakefile
|
99
102
|
- Vagrantfile
|
100
103
|
- finishing_moves.gemspec
|
101
104
|
- lib/finishing_moves.rb
|
105
|
+
- lib/finishing_moves/array.rb
|
106
|
+
- lib/finishing_moves/date_and_time.rb
|
107
|
+
- lib/finishing_moves/enumerable.rb
|
102
108
|
- lib/finishing_moves/fixnum.rb
|
103
109
|
- lib/finishing_moves/hash.rb
|
110
|
+
- lib/finishing_moves/kernel.rb
|
104
111
|
- lib/finishing_moves/object.rb
|
112
|
+
- lib/finishing_moves/string.rb
|
105
113
|
- lib/finishing_moves/to_bool.rb
|
106
114
|
- lib/finishing_moves/version.rb
|
107
115
|
- provision.sh
|
116
|
+
- spec/array_spec.rb
|
117
|
+
- spec/enumerable_spec.rb
|
108
118
|
- spec/fixnum_spec.rb
|
109
119
|
- spec/hash_spec.rb
|
120
|
+
- spec/kernel_spec.rb
|
110
121
|
- spec/object_spec.rb
|
111
122
|
- spec/spec_helper.rb
|
123
|
+
- spec/string_spec.rb
|
112
124
|
- spec/to_bool_spec.rb
|
113
125
|
homepage: https://github.com/forgecrafted/finishing_moves
|
114
126
|
licenses:
|
115
127
|
- MIT
|
116
128
|
metadata: {}
|
117
|
-
post_install_message:
|
129
|
+
post_install_message: |
|
130
|
+
********************************************************************************
|
131
|
+
|
132
|
+
Thank you for installing Finishing Moves!
|
133
|
+
|
134
|
+
Built and maintained by Forge Software
|
135
|
+
www.forgecrafted.com
|
136
|
+
|
137
|
+
Does your project or organization use this gem? Add it to the showcase page.
|
138
|
+
https://github.com/forgecrafted/finishing_moves/wiki/showcase
|
139
|
+
|
140
|
+
********************************************************************************
|
118
141
|
rdoc_options: []
|
119
142
|
require_paths:
|
120
143
|
- lib
|
@@ -135,8 +158,12 @@ signing_key:
|
|
135
158
|
specification_version: 4
|
136
159
|
summary: Small, focused, incredibly useful methods added to core Ruby classes.
|
137
160
|
test_files:
|
161
|
+
- spec/array_spec.rb
|
162
|
+
- spec/enumerable_spec.rb
|
138
163
|
- spec/fixnum_spec.rb
|
139
164
|
- spec/hash_spec.rb
|
165
|
+
- spec/kernel_spec.rb
|
140
166
|
- spec/object_spec.rb
|
141
167
|
- spec/spec_helper.rb
|
168
|
+
- spec/string_spec.rb
|
142
169
|
- spec/to_bool_spec.rb
|