evt-collection 1.1.0.6 → 2.4.1.0

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
  SHA256:
3
- metadata.gz: f7709eba53ae59d0111d893d9195b1fdf55bbebd29dcc74103f00707809b79c1
4
- data.tar.gz: 9f9b5f172c0109abda13bf7544916db3d8031fbe19a7d04d33322b16e0f07dd2
3
+ metadata.gz: 6b9873a9d37bf4b855172f564e19e47a9605e944a0b843f304183d3b8426dbf2
4
+ data.tar.gz: e0aec9f5c363c823fb726140a4bdc6398c47887967b3602e0665993606f84ee6
5
5
  SHA512:
6
- metadata.gz: 1c18eb19d1b98c917cf02e6a0a271a6221bf5e60e77d05d1ffe6aadf8288f57c2fc5207bcb41f501b24077219ed38cf2756060fe257c4415519f00e2e2d08caf
7
- data.tar.gz: 8a2820ab543bbdf5f01c9ca08366331192591c223af6e9c3e6f22e8e507efd631f85619cf91f743b5bfd2264b3908afc1d2bfbfb74c5e83db9c8dbe6f0da0490
6
+ metadata.gz: 3b524d393b8d526b4d38f60c1a2d11d48b9e136123289251eac790235c4d0b1eff2b1b17b5425618e544c89e53efa1d9212d237235a8de7b1479b007ef7270d3
7
+ data.tar.gz: ed544b2dcefb07112a0879937ae1e399319a0b092ba1e0d7849506de00c3bcc4657bc6aca9c0d7a329b63ba6eee4e03de52f5078340c9cfee0e62f05d8480329
data/lib/collection.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require 'set'
2
2
 
3
- require 'collection/set'
3
+ require 'collection/generic'
4
4
  require 'collection/collection'
5
+ require 'collection/array'
6
+ require 'collection/set'
@@ -0,0 +1,9 @@
1
+ module Collection
2
+ class Array
3
+ include Collection
4
+
5
+ def content
6
+ @content ||= ::Array.new
7
+ end
8
+ end
9
+ end
@@ -1,10 +1,46 @@
1
1
  module Collection
2
- def self.[](type_parameter)
3
- Set[type_parameter]
2
+ def self.included(cls)
3
+ cls.include Enumerable
4
+ cls.extend Generic
4
5
  end
5
6
 
7
+ attr_reader :type_parameter
8
+
9
+ def initialize(type_parameter)
10
+ @type_parameter = type_parameter
11
+ end
12
+
13
+ def add(val)
14
+ if not val.is_a?(type_parameter)
15
+ raise ArgumentError, "#{val.inspect} must be a #{type_parameter.name}"
16
+ end
17
+
18
+ content << val
19
+
20
+ self
21
+ end
22
+ alias :<< :add
23
+
24
+ def each(&action)
25
+ content.each(&action)
26
+ end
27
+
28
+ def empty?
29
+ content.empty?
30
+ end
31
+
32
+ def clear
33
+ content.clear
34
+ self
35
+ end
36
+
37
+ def ==(other)
38
+ other.class == self.class && other.type_parameter == self.type_parameter && other.content == self.content
39
+ end
40
+ alias :eql? :==
41
+
6
42
  def self.Set(items)
7
- items = Array(items)
43
+ items = Kernel::Array(items)
8
44
 
9
45
  raise ArgumentError, "Collection can't be empty" if items.empty?
10
46
 
@@ -13,9 +49,25 @@ module Collection
13
49
  set = Set[type_parameter].new
14
50
 
15
51
  items.each do |member|
16
- set.add member
52
+ set.add(member)
17
53
  end
18
54
 
19
55
  set
20
56
  end
57
+
58
+ def self.Array(items)
59
+ items = Kernel::Array(items)
60
+
61
+ raise ArgumentError, "Collection can't be empty" if items.empty?
62
+
63
+ type_parameter = items[0].class
64
+
65
+ array = Array[type_parameter].new
66
+
67
+ items.each do |member|
68
+ array.add(member)
69
+ end
70
+
71
+ array
72
+ end
21
73
  end
@@ -0,0 +1,45 @@
1
+ module Collection
2
+ module Generic
3
+ def [](type_parameter)
4
+ type_parameter_name = constant_name(type_parameter)
5
+
6
+ cls = nil
7
+ unless self.const_defined?(type_parameter_name, false)
8
+ cls = define_class(type_parameter)
9
+ set_collection_constant(type_parameter, cls)
10
+ else
11
+ cls = const_get(type_parameter_name)
12
+ end
13
+
14
+ cls
15
+ end
16
+
17
+ def define_class(type_parameter)
18
+ cls = Class.new(self) do
19
+ def initialize; end
20
+
21
+ define_method :type_parameter do
22
+ type_parameter
23
+ end
24
+ end
25
+
26
+ set_collection_constant(type_parameter, cls)
27
+
28
+ cls
29
+ end
30
+
31
+ def constant_name(constant)
32
+ constant.name.gsub('::', '_')
33
+ end
34
+
35
+ def set_collection_constant(constant, cls)
36
+ class_name = constant_name(constant)
37
+
38
+ unless self.const_defined?(class_name, false)
39
+ self.const_set(class_name, cls)
40
+ end
41
+
42
+ class_name
43
+ end
44
+ end
45
+ end
@@ -1,100 +1,6 @@
1
1
  module Collection
2
2
  class Set
3
- include Enumerable
4
-
5
- attr_reader :type_parameter
6
-
7
- def initialize(type_parameter)
8
- @type_parameter = type_parameter
9
- end
10
-
11
- def self.[](type_parameter)
12
- type_parameter_name = constant_name(type_parameter)
13
-
14
- cls = nil
15
- unless self.const_defined?(type_parameter_name, false)
16
- cls = define_class(type_parameter)
17
- set_collection_constant(type_parameter, cls)
18
- else
19
- cls = const_get(type_parameter_name)
20
- end
21
-
22
- cls
23
- end
24
-
25
- def self.define_class(type_parameter)
26
- cls = Class.new(self) do
27
- def initialize; end
28
-
29
- define_method :type_parameter do
30
- type_parameter
31
- end
32
- end
33
-
34
- set_collection_constant(type_parameter, cls)
35
-
36
- cls
37
- end
38
-
39
- def self.constant_name(constant)
40
- constant.name.gsub('::', '_')
41
- end
42
-
43
- def self.set_collection_constant(constant, cls)
44
- class_name = constant_name(constant)
45
-
46
- unless self.const_defined?(class_name, false)
47
- self.const_set(class_name, cls)
48
- end
49
-
50
- class_name
51
- end
52
-
53
- def add(val)
54
- vals = Array(val)
55
-
56
- vals.each do |val|
57
- raise ArgumentError, "#{val.inspect} must be a #{type_parameter.name}" unless val.is_a? type_parameter
58
- content.add(val)
59
- end
60
-
61
- self
62
- end
63
- alias :<< :add
64
-
65
- def entry?(val=nil, &predicate)
66
- if !block_given?
67
- predicate = lambda { |m| m == val }
68
- end
69
-
70
- entries(&predicate).length > 0
71
- end
72
-
73
- def entries(&predicate)
74
- content.select(&predicate)
75
- end
76
-
77
- def entry(&predicate)
78
- content.find(&predicate)
79
- end
80
-
81
- def each(&action)
82
- content.each(&action)
83
- end
84
-
85
- def entries?
86
- !content.empty?
87
- end
88
-
89
- def empty?
90
- content.empty?
91
- end
92
-
93
- def length
94
- content.length
95
- end
96
- alias :size :length
97
- alias :count :length
3
+ include Collection
98
4
 
99
5
  def content
100
6
  @content ||= ::Set.new
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evt-collection
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0.6
4
+ version: 2.4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Eventide Project
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-09 00:00:00.000000000 Z
11
+ date: 2021-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test_bench
@@ -31,16 +31,18 @@ extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
33
  - lib/collection.rb
34
+ - lib/collection/array.rb
34
35
  - lib/collection/collection.rb
35
36
  - lib/collection/controls.rb
36
37
  - lib/collection/controls/array.rb
37
38
  - lib/collection/controls/member.rb
39
+ - lib/collection/generic.rb
38
40
  - lib/collection/set.rb
39
41
  homepage: https://github.com/eventide-project/collection
40
42
  licenses:
41
43
  - MIT
42
44
  metadata: {}
43
- post_install_message:
45
+ post_install_message:
44
46
  rdoc_options: []
45
47
  require_paths:
46
48
  - lib
@@ -55,8 +57,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
57
  - !ruby/object:Gem::Version
56
58
  version: '0'
57
59
  requirements: []
58
- rubygems_version: 3.0.1
59
- signing_key:
60
+ rubygems_version: 3.1.2
61
+ signing_key:
60
62
  specification_version: 4
61
63
  summary: Type-checked set
62
64
  test_files: []