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
76
77
78
79
80
81
82
83
84
|
# File 'lib/threatinator/model/collection.rb', line 76
def ==(other)
if self.equal?(other)
return true
elsif other.instance_of?(self.class)
@collection == other.instance_variable_get(:@collection)
else
false
end
end
|
#collect! ⇒ Object
37
38
39
40
|
# File 'lib/threatinator/model/collection.rb', line 37
def collect!
block_given? or return enum_for(__method__)
@collection.replace(@collection.class.new(@collection) { |o| yield(o) })
end
|
#count ⇒ Integer
Also known as:
size, length
Returns the number of members in the collection.
51
52
53
|
# File 'lib/threatinator/model/collection.rb', line 51
def count
@collection.count
end
|
#delete(o) ⇒ Object
42
43
44
|
# File 'lib/threatinator/model/collection.rb', line 42
def delete(o)
@collection.delete(o)
end
|
#delete?(o) ⇒ Boolean
46
47
48
|
# File 'lib/threatinator/model/collection.rb', line 46
def delete?(o)
@collection.delete?(o)
end
|
#each ⇒ Object
65
66
67
68
|
# File 'lib/threatinator/model/collection.rb', line 65
def each
return to_enum(:each) unless block_given?
@collection.each { |v| yield v }
end
|
#empty? ⇒ Boolean
Returns true if empty, false otherwise.
33
34
35
|
# File 'lib/threatinator/model/collection.rb', line 33
def empty?
@collection.empty?
end
|
#include?(member) ⇒ Boolean
Also known as:
member?
27
28
29
|
# File 'lib/threatinator/model/collection.rb', line 27
def include?(member)
@collection.include?(member)
end
|
#list ⇒ Object
70
71
72
73
74
|
# File 'lib/threatinator/model/collection.rb', line 70
def list
@collection.to_a.collect {|item|
item.to_s
}
end
|
#to_ary ⇒ Object
Also known as:
to_a
57
58
59
|
# File 'lib/threatinator/model/collection.rb', line 57
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
|