clazz_extensions 0.0.5 → 0.0.6
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19579ab82bde80d8d2495b2998e10b7627aaecd2
|
4
|
+
data.tar.gz: 91c83e43afea105f3dfe36963b46e7d6e213bb35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2aa649cbc60e587af85d089aac3beedc123854f8d41fb1f4adae167ad62132eb1c31f6d99d06ad87920c453015b699d49b2307dd6cf04cc6dfab53058a2f0b5f
|
7
|
+
data.tar.gz: 5a8d1095a94a56dc64fecb5b27fa60131d5b452e586b50ecc7edb36a77070f0753c5afffcbb6ed57fd98c62729b0a0eef6be336d686c0977d38fbb011aa0ae85
|
@@ -11,9 +11,14 @@ module ClazzExtensions
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def duplication!( clazz, _ )
|
14
|
-
|
15
|
-
|
14
|
+
dupli = duplication( clazz, _ )
|
15
|
+
array = clazz.dup
|
16
|
+
array.each { |v|
|
17
|
+
unless dupli.index( v )
|
18
|
+
clazz.delete( v )
|
19
|
+
end
|
16
20
|
}
|
21
|
+
clazz.uniq!
|
17
22
|
end
|
18
23
|
|
19
24
|
def unduplication( clazz, _ )
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "clazz_extensions"
|
2
|
+
|
3
|
+
describe "ClazzExtensions::Array" do
|
4
|
+
before do
|
5
|
+
@array = ClazzExtensions::Array.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "duplication" do
|
9
|
+
#[1,2,3,1].duplication
|
10
|
+
expect( @array.duplication( [1,2,3,1], nil ) ).to eq( [1] )
|
11
|
+
#[1,2,3,1,3].duplication
|
12
|
+
array = [1,2,3,1,3]
|
13
|
+
expect( @array.duplication( array , nil ) ).to eq( [1,3] )
|
14
|
+
expect( array ).to eq( [1,2,3,1,3] )
|
15
|
+
end
|
16
|
+
|
17
|
+
it "blank?" do
|
18
|
+
#[].blank?
|
19
|
+
expect( @array.blank?( [] , nil ) ).to eq( true )
|
20
|
+
#[1,2,3].blank?
|
21
|
+
expect( @array.blank?( [1,2,3], nil ) ).to eq( false )
|
22
|
+
end
|
23
|
+
|
24
|
+
it "duplication!" do
|
25
|
+
#[1,2,3,1].duplication!
|
26
|
+
array = [1,2,3,1]
|
27
|
+
@array.duplication!( array, nil )
|
28
|
+
expect( array ).to eq( [1] )
|
29
|
+
#[1,2,3,1,3].duplication!
|
30
|
+
array = [1,2,3,1,3]
|
31
|
+
@array.duplication!( array, nil )
|
32
|
+
expect( array ).to eq( [1,3] )
|
33
|
+
end
|
34
|
+
|
35
|
+
it "unduplication" do
|
36
|
+
#[1,2,3,1].unduplication
|
37
|
+
expect( @array.unduplication( [1,2,3,1], nil ) ).to eq( [2,3] )
|
38
|
+
#[1,2,3,1,3].unduplication
|
39
|
+
array = [1,2,3,1,3]
|
40
|
+
expect( @array.unduplication( array , nil ) ).to eq( [2] )
|
41
|
+
expect( array ).to eq( [1,2,3,1,3] )
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "clazz_extensions"
|
2
|
+
|
3
|
+
describe "ClazzExtensions::String" do
|
4
|
+
before do
|
5
|
+
@string = ClazzExtensions::String.new
|
6
|
+
end
|
7
|
+
it "classify" do
|
8
|
+
# "hoge".classify
|
9
|
+
expect( @string.classify( "hoge" , nil ) ).to eq( "Hoge" )
|
10
|
+
# "foo_bar".classify
|
11
|
+
expect( @string.classify( "foo_bar", nil ) ).to eq( "FooBar" )
|
12
|
+
# "foo/bar".classify
|
13
|
+
expect( @string.classify( "foo/bar", nil ) ).to eq( "Foo::Bar" )
|
14
|
+
end
|
15
|
+
|
16
|
+
it "blank?" do
|
17
|
+
# "".blank?
|
18
|
+
expect( @string.blank?( "" , nil ) ).to eq( true )
|
19
|
+
# "foo_bar".blank?
|
20
|
+
expect( @string.blank?( "foo_bar", nil ) ).to eq( false )
|
21
|
+
end
|
22
|
+
|
23
|
+
it "to_const" do
|
24
|
+
# "".to_const
|
25
|
+
expect( @string.to_const( "" , nil ) ).to eq( nil )
|
26
|
+
# "foo_bar".to_const
|
27
|
+
expect( @string.to_const( "foo_bar", nil ) ).to eq( nil )
|
28
|
+
# "array".to_const
|
29
|
+
expect( @string.to_const( "array" , nil ) ).to eq( Array )
|
30
|
+
# "Array".to_const
|
31
|
+
expect( @string.to_const( "Array" , nil ) ).to eq( Array )
|
32
|
+
end
|
33
|
+
|
34
|
+
it "classify2" do
|
35
|
+
# "hoge".classify2( "hoge" )
|
36
|
+
expect( @string.classify2( "hoge" , ["hoge"] ) ).to eq( "HogeHoge" )
|
37
|
+
# "hoge".classify2( "hoge", "hoge" )
|
38
|
+
expect( @string.classify2( "hoge" , ["hoge", "hoge"] ) ).to eq( "HogeHogeHoge" )
|
39
|
+
end
|
40
|
+
|
41
|
+
it "each" do
|
42
|
+
#array = []
|
43
|
+
#"hoge".each do |c|
|
44
|
+
# array << c.succ
|
45
|
+
#end
|
46
|
+
array = []
|
47
|
+
@string.each( "hoge", nil ) do |c|
|
48
|
+
array << c.succ
|
49
|
+
end
|
50
|
+
expect( array ).to eq( ["i","p", "h", "f" ] )
|
51
|
+
end
|
52
|
+
|
53
|
+
it "each_with_index" do
|
54
|
+
#hash = {}
|
55
|
+
#"hoge".each do |c|
|
56
|
+
# hash[i] = c
|
57
|
+
#end
|
58
|
+
hash = {}
|
59
|
+
@string.each_with_index( "hoge", nil ) do |c,i|
|
60
|
+
hash[i] = c
|
61
|
+
end
|
62
|
+
expect( hash ).to eq( {0 => "h", 1 => "o", 2 => "g", 3 => "e"} )
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clazz_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hiraokashogi
|
@@ -59,6 +59,8 @@ files:
|
|
59
59
|
- lib/clazz_extensions/base.rb
|
60
60
|
- lib/clazz_extensions/string.rb
|
61
61
|
- lib/clazz_extensions/version.rb
|
62
|
+
- spec/clazz_extensions/array_spec.rb
|
63
|
+
- spec/clazz_extensions/string_spec.rb
|
62
64
|
- spec/clazz_extensions_spec.rb
|
63
65
|
- spec/spec_helper.rb
|
64
66
|
homepage: https://github.com/hiraoka/clazz_extensions
|
@@ -86,6 +88,8 @@ signing_key:
|
|
86
88
|
specification_version: 4
|
87
89
|
summary: Add utility methods on defined class.
|
88
90
|
test_files:
|
91
|
+
- spec/clazz_extensions/array_spec.rb
|
92
|
+
- spec/clazz_extensions/string_spec.rb
|
89
93
|
- spec/clazz_extensions_spec.rb
|
90
94
|
- spec/spec_helper.rb
|
91
95
|
has_rdoc:
|