flash_extensions 0.0.1 → 1.0.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/.travis.yml +2 -3
- data/README.md +204 -83
- data/flash_extensions.gemspec +3 -3
- data/lib/flash_extensions.rb +2 -0
- data/lib/flash_extensions/extensions/array_extension.rb +5 -5
- data/lib/flash_extensions/extensions/enumerable_extension.rb +91 -0
- data/lib/flash_extensions/extensions/hash_extension.rb +24 -8
- data/lib/flash_extensions/extensions/numeric_extension.rb +17 -0
- data/lib/flash_extensions/extensions/object_extension.rb +6 -6
- data/lib/flash_extensions/extensions/string_extension.rb +81 -29
- data/lib/flash_extensions/extensions/time_extension.rb +2 -2
- data/lib/flash_extensions/version.rb +1 -1
- data/spec/lib/array_extension_spec.rb +4 -4
- data/spec/lib/enumerable_extension_spec.rb +116 -0
- data/spec/lib/hash_extension_spec.rb +52 -0
- data/spec/lib/numeric_extension_spec.rb +35 -0
- data/spec/lib/object_extension_spec.rb +2 -0
- data/spec/lib/string_extension_spec.rb +104 -1
- data/spec/lib/time_extension_spec.rb +2 -0
- metadata +12 -6
@@ -78,7 +78,7 @@ class Time
|
|
78
78
|
"time_zone_name" => "Z"
|
79
79
|
}
|
80
80
|
|
81
|
-
|
81
|
+
strftime(
|
82
82
|
if string.empty? || string.nil?
|
83
83
|
"%Y-%m-%d %H:%M %z"
|
84
84
|
else
|
@@ -162,7 +162,7 @@ class Time
|
|
162
162
|
time_imperical_tzn: "%I:%M %P %Z"
|
163
163
|
}
|
164
164
|
|
165
|
-
|
165
|
+
strftime(format_units[key])
|
166
166
|
end
|
167
167
|
|
168
168
|
end
|
@@ -12,15 +12,15 @@ describe Array do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
describe "#
|
15
|
+
describe "#remove_first" do
|
16
16
|
it "to be this is a test" do
|
17
|
-
expect(["1", "2", "3"].
|
17
|
+
expect(["1", "2", "3"].remove_first).to eq(["2", "3"])
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
describe "#
|
21
|
+
describe "#remove_last" do
|
22
22
|
it "to be this is a test" do
|
23
|
-
expect(["1", "2", "3"].
|
23
|
+
expect(["1", "2", "3"].remove_last).to eq(["1", "2"])
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Enumerable do
|
4
|
+
|
5
|
+
describe "#average" do
|
6
|
+
it "to be 0" do
|
7
|
+
expect([].average).to eq(0)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "to be nil" do
|
11
|
+
expect([].average(nil)).to eq(nil)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "to be 2" do
|
15
|
+
expect([1, 2, 3].average).to eq(2)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "to be 2.5" do
|
19
|
+
expect([1, 2, 3, 4].average).to eq(2.5)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#drop_last" do
|
24
|
+
it "to be [2, 3]" do
|
25
|
+
expect([1, 2, 3].drop_last(1)).to eq([1, 2])
|
26
|
+
end
|
27
|
+
|
28
|
+
it "to be []" do
|
29
|
+
expect([].drop_last(3)).to eq([])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#drop_last_while" do
|
34
|
+
it "to be [1, 2]" do
|
35
|
+
expect([1, 2, 3].drop_last_while(&:odd?)).to eq([1, 2])
|
36
|
+
end
|
37
|
+
|
38
|
+
it "to be []" do
|
39
|
+
expect([].take_last_while(&:odd?)).to eq([])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#exactly?" do
|
44
|
+
it "to be true" do
|
45
|
+
expect([1, false, nil].exactly?(1)).to eq(true)
|
46
|
+
expect([false, nil].exactly?(0)).to eq(true)
|
47
|
+
expect([1, 2, 3].exactly?(3)).to eq(true)
|
48
|
+
expect([1, 2, 3, 4].exactly?(1) { |n| n > 3 }).to eq(true)
|
49
|
+
expect([1, 2, 3, 4].exactly?(2, &:even?)).to eq(true)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "to be false" do
|
53
|
+
expect([].exactly?(1)).to eq(false)
|
54
|
+
expect([1, false, nil].exactly?(3)).to eq(false)
|
55
|
+
expect([1, 1, 3, 3].exactly?(2, &:even?)).to eq(false)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#frequencies" do
|
60
|
+
it "to be {}" do
|
61
|
+
expect([].frequencies).to eq({})
|
62
|
+
end
|
63
|
+
|
64
|
+
it "to be { 1 => 2, :symbol => 2, 'string' => 1, 3 => 1 }" do
|
65
|
+
expect([1, :symbol, 'string', 3, :symbol, 1].frequencies).to eq({ 1 => 2, :symbol => 2, 'string' => 1, 3 => 1 })
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#several?" do
|
70
|
+
it "to be true" do
|
71
|
+
expect([1, 2, 3].several?).to eq(true)
|
72
|
+
expect([1, 2, 3, 4].several?(&:even?)).to eq(true)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "to be false" do
|
76
|
+
expect([].several?).to eq(false)
|
77
|
+
expect([1, false, nil].several?).to eq(false)
|
78
|
+
expect([1, 1, 3, 3].several?(&:even?)).to eq(false)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "#sum" do
|
83
|
+
it "to be 0" do
|
84
|
+
expect([].sum).to eq(0)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "to be nil" do
|
88
|
+
expect([].sum(nil)).to eq(nil)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "to be 6" do
|
92
|
+
expect([1, 2, 3].sum).to eq(6)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "#take_last" do
|
97
|
+
it "to be [2, 3]" do
|
98
|
+
expect([1, 2, 3].take_last(2)).to eq([2, 3])
|
99
|
+
end
|
100
|
+
|
101
|
+
it "to be []" do
|
102
|
+
expect([].take_last(3)).to eq([])
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "#take_last_while" do
|
107
|
+
it "to be [3, 5]" do
|
108
|
+
expect([1, 2, 3, 5].take_last_while(&:odd?)).to eq([3, 5])
|
109
|
+
end
|
110
|
+
|
111
|
+
it "to be []" do
|
112
|
+
expect([].take_last_while(&:odd?)).to eq([])
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
@@ -1,6 +1,39 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Hash do
|
4
|
+
|
5
|
+
describe "#except" do
|
6
|
+
it "to be {}" do
|
7
|
+
expect({}.except(:foo)).to eq({})
|
8
|
+
end
|
9
|
+
|
10
|
+
it "to be { :foo => 1 }" do
|
11
|
+
expect({ :foo => 1, :baz => 2, :bar => 3 }.except(:baz, :bar)).to eq({ :foo => 1 })
|
12
|
+
expect({ foo: 1, baz: 2, bar: 3 }.except(:baz, :bar)).to eq({ foo: 1 })
|
13
|
+
end
|
14
|
+
|
15
|
+
it "to be { :baz => 2, :bar => 3 }" do
|
16
|
+
expect({ :foo => 1, :baz => 2, :bar => 3 }.except(:foo)).to eq({ :baz => 2, :bar => 3 })
|
17
|
+
expect({ foo: 1, baz: 2, bar: 3 }.except(:foo)).to eq({ baz: 2, bar: 3 })
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#only" do
|
22
|
+
it "to be {}" do
|
23
|
+
expect({}.only(:foo)).to eq({})
|
24
|
+
end
|
25
|
+
|
26
|
+
it "to be { :foo => 1 }" do
|
27
|
+
expect({ :foo => 1, :baz => 2, :bar => 3 }.only(:foo)).to eq({ :foo => 1 })
|
28
|
+
expect({ foo: 1, baz: 2, bar: 3 }.only(:foo)).to eq({ foo: 1 })
|
29
|
+
end
|
30
|
+
|
31
|
+
it "to be { :baz => 2, :bar => 3 }" do
|
32
|
+
expect({ :foo => 1, :baz => 2, :bar => 3 }.only(:baz, :bar)).to eq({ :baz => 2, :bar => 3 })
|
33
|
+
expect({ foo: 1, baz: 2, bar: 3 }.only(:baz, :bar)).to eq({ baz: 2, bar: 3 })
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
4
37
|
describe "#rename_keys" do
|
5
38
|
it "to be [:baz, :bar]" do
|
6
39
|
expect({ foo: 'foo', baz: 'baz' }.rename_keys(foo: :bar).keys).to eq([:baz, :bar])
|
@@ -19,6 +52,24 @@ describe Hash do
|
|
19
52
|
end
|
20
53
|
end
|
21
54
|
|
55
|
+
describe "#rename_keys!" do
|
56
|
+
it "to be [:baz, :bar]" do
|
57
|
+
expect({ foo: 'foo', baz: 'baz' }.rename_keys!(foo: :bar).keys).to eq([:baz, :bar])
|
58
|
+
end
|
59
|
+
|
60
|
+
it "to be [:foo, 'tick']" do
|
61
|
+
expect({ foo: 'foo', 'baz' => 'baz' }.rename_keys!('baz' => 'tick').keys).to eq([:foo, 'tick'])
|
62
|
+
end
|
63
|
+
|
64
|
+
it "to be [:bar, :tick]" do
|
65
|
+
expect({ foo: 'foo', baz: 'baz' }.rename_keys!(foo: :bar, baz: :tick).keys).to eq([:bar, :tick])
|
66
|
+
end
|
67
|
+
|
68
|
+
it "to be [:bar, 'tick']" do
|
69
|
+
expect({ foo: 'foo', 'baz' => 'baz' }.rename_keys!(foo: :bar, 'baz' => 'tick').keys).to eq([:bar, 'tick'])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
22
73
|
describe "#stringify_keys(!)" do
|
23
74
|
it "to be ['foo', 'bar']" do
|
24
75
|
expect({ foo: 'foo', 'bar' => 'bar' }.stringify_keys.keys).to eq(['foo', 'bar'])
|
@@ -39,4 +90,5 @@ describe Hash do
|
|
39
90
|
expect({ 'foo_Bar' => 'example', bazBar: 'string' }.symbolize_and_underscore_keys.keys).to eq([:foo_bar, :baz_bar])
|
40
91
|
end
|
41
92
|
end
|
93
|
+
|
42
94
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Numeric do
|
4
|
+
|
5
|
+
describe "#multiple_of?" do
|
6
|
+
it "to be true" do
|
7
|
+
expect(9.multiple_of?(3)).to eq(true)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "to be false" do
|
11
|
+
expect(10.multiple_of?(3)).to eq(false)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#negative?" do
|
16
|
+
it "to be true" do
|
17
|
+
expect(-1.negative?).to eq(true)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "to be false" do
|
21
|
+
expect(1.negative?).to eq(false)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#positive?" do
|
26
|
+
it "to be true" do
|
27
|
+
expect(1.positive?).to eq(true)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "to be false" do
|
31
|
+
expect(-1.positive?).to eq(false)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe String do
|
4
|
+
|
4
5
|
describe "#camelize" do
|
5
6
|
it "to be ExampleString" do
|
6
7
|
expect("example_string".camelize).to eq("ExampleString")
|
@@ -11,6 +12,16 @@ describe String do
|
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
15
|
+
describe "#camelize!" do
|
16
|
+
it "to be ExampleString" do
|
17
|
+
expect("example_string".camelize!).to eq("ExampleString")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "to be exampleString" do
|
21
|
+
expect("example_string".camelize!(:lower)).to eq("exampleString")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
14
25
|
describe "#ends_with?" do
|
15
26
|
it "to be true" do
|
16
27
|
expect("".ends_with?("")).to eq(true)
|
@@ -35,6 +46,14 @@ describe String do
|
|
35
46
|
end
|
36
47
|
end
|
37
48
|
|
49
|
+
describe "#humanize!" do
|
50
|
+
it "to be Example string test" do
|
51
|
+
expect("example_string_test".humanize!).to eq("Example string test")
|
52
|
+
expect("exampleStringTest".humanize!).to eq("Example string test")
|
53
|
+
expect("ExampleStringTest".humanize!).to eq("Example string test")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
38
57
|
describe "#starts_with?" do
|
39
58
|
it "to be true" do
|
40
59
|
expect("".starts_with?("")).to eq(true)
|
@@ -60,6 +79,15 @@ describe String do
|
|
60
79
|
end
|
61
80
|
end
|
62
81
|
|
82
|
+
describe "#titleize!" do
|
83
|
+
it "to be Example String Test" do
|
84
|
+
expect("example string test".titleize!).to eq("Example String Test")
|
85
|
+
expect("Example string Test".titleize!).to eq("Example String Test")
|
86
|
+
expect("ExampleStringTest".titleize!).to eq("Example String Test")
|
87
|
+
expect("Example_string_test".titleize!).to eq("Example String Test")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
63
91
|
describe "#underscore" do
|
64
92
|
it "to be example_string" do
|
65
93
|
expect("ExampleString".underscore).to eq("example_string")
|
@@ -69,6 +97,15 @@ describe String do
|
|
69
97
|
end
|
70
98
|
end
|
71
99
|
|
100
|
+
describe "#underscore!" do
|
101
|
+
it "to be example_string" do
|
102
|
+
expect("ExampleString".underscore!).to eq("example_string")
|
103
|
+
expect("exampleString".underscore!).to eq("example_string")
|
104
|
+
expect("example_string".underscore!).to eq("example_string")
|
105
|
+
expect("example_String".underscore!).to eq("example_string")
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
72
109
|
describe "#domain" do
|
73
110
|
it "to be test" do
|
74
111
|
expect("".domain).to eq("")
|
@@ -120,6 +157,12 @@ describe String do
|
|
120
157
|
end
|
121
158
|
end
|
122
159
|
|
160
|
+
describe "#gnix!" do
|
161
|
+
it "to be this that " do
|
162
|
+
expect("this thing that thing".gnix!("thing")).to eq("this that ")
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
123
166
|
describe "#mixedcase?" do
|
124
167
|
it "to be true" do
|
125
168
|
expect("Mixedcase".mixedcase?).to eq(true)
|
@@ -138,6 +181,12 @@ describe String do
|
|
138
181
|
end
|
139
182
|
end
|
140
183
|
|
184
|
+
describe "#nix!" do
|
185
|
+
it "to be this that thing" do
|
186
|
+
expect("this thing that thing".nix!("thing")).to eq("this that thing")
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
141
190
|
describe "#pollute" do
|
142
191
|
it "to be t^--^--^e^--^--^s^--^--^t^--^--^" do
|
143
192
|
expect("test".pollute).to eq("t^--^--^e^--^--^s^--^--^t^--^--^")
|
@@ -186,6 +235,38 @@ describe String do
|
|
186
235
|
end
|
187
236
|
end
|
188
237
|
|
238
|
+
describe "#slugify!" do
|
239
|
+
it "to be example" do
|
240
|
+
expect("example".slugify!).to eq("example")
|
241
|
+
end
|
242
|
+
|
243
|
+
it "to be example-string" do
|
244
|
+
expect("example string".slugify!).to eq("example-string")
|
245
|
+
end
|
246
|
+
|
247
|
+
it "to be example-string-test" do
|
248
|
+
expect("Example string @@@ test!".slugify!).to eq("example-string-test")
|
249
|
+
end
|
250
|
+
|
251
|
+
it "to be a-real-doozie" do
|
252
|
+
expect(" A REal Doozi\"e? \' ".slugify!).to eq("a-real-doozie")
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
describe "#squish" do
|
257
|
+
it "to be example test" do
|
258
|
+
expect("example test".squish).to eq("example test")
|
259
|
+
expect(" example test ".squish).to eq("example test")
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
describe "#squish!" do
|
264
|
+
it "to be example test" do
|
265
|
+
expect("example test".squish!).to eq("example test")
|
266
|
+
expect(" example test ".squish!).to eq("example test")
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
189
270
|
describe "#strip_tags" do
|
190
271
|
it "to be example" do
|
191
272
|
expect("example".strip_tags).to eq("example")
|
@@ -200,13 +281,34 @@ describe String do
|
|
200
281
|
end
|
201
282
|
end
|
202
283
|
|
203
|
-
describe "#strip_tags" do
|
284
|
+
describe "#strip_tags!" do
|
285
|
+
it "to be example" do
|
286
|
+
expect("example".strip_tags!).to eq("example")
|
287
|
+
end
|
288
|
+
|
289
|
+
it "to be click" do
|
290
|
+
expect("<a href='http://example.com'>click</a>".strip_tags!).to eq("click")
|
291
|
+
end
|
292
|
+
|
293
|
+
it "to be this is bold and emphatic" do
|
294
|
+
expect("this is <b>bold</b> and <em>emphatic</em>".strip_tags!).to eq("this is bold and emphatic")
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
describe "#strip_whitespace" do
|
204
299
|
it "to be example" do
|
205
300
|
expect("example string test".strip_whitespace).to eq("example string test")
|
206
301
|
expect(" this \t is also a test ".strip_whitespace).to eq("this is also a test")
|
207
302
|
end
|
208
303
|
end
|
209
304
|
|
305
|
+
describe "#strip_whitespace!" do
|
306
|
+
it "to be example" do
|
307
|
+
expect("example string test".strip_whitespace!).to eq("example string test")
|
308
|
+
expect(" this \t is also a test ".strip_whitespace!).to eq("this is also a test")
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
210
312
|
describe "#truncate_preserving_words" do
|
211
313
|
it "to be example string" do
|
212
314
|
expect("example string".truncate_preserving_words).to eq("example string")
|
@@ -233,4 +335,5 @@ describe String do
|
|
233
335
|
expect("Mixedcase string".upcase?).to eq(false)
|
234
336
|
end
|
235
337
|
end
|
338
|
+
|
236
339
|
end
|