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.



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

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)



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

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



14
15
16
# File 'lib/nucop/helpers/cop_set.rb', line 14

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

#cop_added?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/nucop/helpers/cop_set.rb', line 35

def cop_added?
  @new_cop_added
end

#to_aObject



31
32
33
# File 'lib/nucop/helpers/cop_set.rb', line 31

def to_a
  @cops.to_a
end