Class: Threatinator::Model::Collection

Inherits:
Object
  • Object
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

#countInteger Also known as: size, length

Returns the number of members in the collection.

Returns:

  • (Integer)

    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

Returns:

  • (Boolean)


46
47
48
# File 'lib/threatinator/model/collection.rb', line 46

def delete?(o)
  @collection.delete?(o)
end

#eachObject

31

pry(#<Threatinator::Plugins::Output::Json>)> event.urls.each{ |uri| p uri.to_s }

teamadrenaline.com/js/t1.exe

> [#<Addressable::URI:0x114c6ec URI:teamadrenaline.com/js/t1.exe>]



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.

Returns:

  • (Boolean)

    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?

Returns:

  • (Boolean)


27
28
29
# File 'lib/threatinator/model/collection.rb', line 27

def include?(member)
  @collection.include?(member)
end

#listObject



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_aryObject 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

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


14
15
16
17
18
# File 'lib/threatinator/model/collection.rb', line 14

def valid_member?(v)
  #:nocov:
  raise NotImplementedError, "#valid_member? not implemented"
  #:nocov:
end