Class: Threatinator::Model::Collection
- Inherits:
-
Object
- Object
- Threatinator::Model::Collection
show all
- Defined in:
- lib/threatinator/model/collection.rb
Instance Method Summary
collapse
Constructor Details
#initialize(values = []) ⇒ Collection
Returns a new instance of Collection.
7
8
9
10
11
12
|
# File 'lib/threatinator/model/collection.rb', line 7
def initialize(values = [])
@collection = Set.new
values.each do |v|
self << v
end
end
|
Instance Method Details
#<<(v) ⇒ Object
20
21
22
23
24
25
|
# File 'lib/threatinator/model/collection.rb', line 20
def <<(v)
unless valid_member?(v)
raise Threatinator::Exceptions::InvalidAttributeError, "Invalid member: #{v.class} '#{v.inspect}'"
end
@collection << v
end
|
#==(other) ⇒ Object
51
52
53
54
55
56
57
58
59
|
# File 'lib/threatinator/model/collection.rb', line 51
def ==(other)
if self.equal?(other)
return true
elsif other.instance_of?(self.class)
@collection == other.instance_variable_get(:@collection)
else
false
end
end
|
#count ⇒ Integer
Returns the number of members in the collection.
37
38
39
|
# File 'lib/threatinator/model/collection.rb', line 37
def count
@collection.count
end
|
#each ⇒ Object
46
47
48
49
|
# File 'lib/threatinator/model/collection.rb', line 46
def each
return to_enum(:each) unless block_given?
@collection.each { |v| yield v }
end
|
#empty? ⇒ Boolean
Returns true if empty, false otherwise.
32
33
34
|
# File 'lib/threatinator/model/collection.rb', line 32
def empty?
@collection.empty?
end
|
#include?(member) ⇒ Boolean
27
28
29
|
# File 'lib/threatinator/model/collection.rb', line 27
def include?(member)
@collection.include?(member)
end
|
#to_ary ⇒ Object
Also known as:
to_a
41
42
43
|
# File 'lib/threatinator/model/collection.rb', line 41
def to_ary
@collection.to_a
end
|
#valid_member?(v) ⇒ Boolean
14
15
16
17
18
|
# File 'lib/threatinator/model/collection.rb', line 14
def valid_member?(v)
raise NotImplementedError, "#valid_member? not implemented"
end
|