Class: Nucop::Helpers::CopCounter
- Inherits:
-
Object
- Object
- Nucop::Helpers::CopCounter
- Defined in:
- lib/nucop/helpers/cop_counter.rb
Class Method Summary collapse
Instance Method Summary collapse
- #count(cops_or_departments) ⇒ Object
-
#initialize(cops) ⇒ CopCounter
constructor
A new instance of CopCounter.
Constructor Details
#initialize(cops) ⇒ CopCounter
Returns a new instance of CopCounter.
14 15 16 |
# File 'lib/nucop/helpers/cop_counter.rb', line 14 def initialize(cops) @cops_by_department = group_by_department(cops) end |
Class Method Details
.count(all_cops, cops_or_departments) ⇒ Object
10 11 12 |
# File 'lib/nucop/helpers/cop_counter.rb', line 10 def self.count(all_cops, cops_or_departments) new(all_cops).count(cops_or_departments) end |
Instance Method Details
#count(cops_or_departments) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/nucop/helpers/cop_counter.rb', line 18 def count(cops_or_departments) cops_or_departments .map do |cop_or_department| if department?(cop_or_department) @cops_by_department.fetch(cop_or_department, []).length else 1 end end .reduce(0, &:+) end |