Class: Nucop::Helpers::CopSet

Inherits:
Object
  • Object
show all
Defined in:
lib/nucop/helpers/cop_set.rb

Instance Method Summary collapse

Constructor Details

#initialize(initial_cops = []) ⇒ CopSet

Returns a new instance of CopSet.



4
5
6
7
8
9
10
# File 'lib/nucop/helpers/cop_set.rb', line 4

def initialize(initial_cops = [])
  @cops = Set.new

  add_cops(initial_cops)

  @new_cop_added = false
end

Instance Method Details

#add_cop(cop) ⇒ Object

add a single cop to the set if a cops department is already included, the cop is not added (it is part of the department already)



19
20
21
22
23
24
25
26
27
# File 'lib/nucop/helpers/cop_set.rb', line 19

def add_cop(cop)
  department = find_department(cop)

  return if department && @cops.include?(department)
  return if @cops.include?(cop)

  @cops << cop
  @new_cop_added = true
end

#add_cops(cops) ⇒ Object



12
13
14
# File 'lib/nucop/helpers/cop_set.rb', line 12

def add_cops(cops)
  cops.each(&method(:add_cop))
end

#cop_added?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/nucop/helpers/cop_set.rb', line 33

def cop_added?
  @new_cop_added
end

#to_aObject



29
30
31
# File 'lib/nucop/helpers/cop_set.rb', line 29

def to_a
  @cops.to_a
end