Class: StoplightAdmin::LightsStats

Inherits:
Object
  • Object
show all
Defined in:
lib/stoplight_admin/lights_stats.rb

Constant Summary collapse

EMPTY_STATS =
{
  count_red: 0, count_yellow: 0, count_green: 0,
  percent_red: 0, percent_yellow: 0, percent_green: 0
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lights) ⇒ LightsStats

Returns a new instance of LightsStats.



22
23
24
# File 'lib/stoplight_admin/lights_stats.rb', line 22

def initialize(lights)
  @lights = lights
end

Instance Attribute Details

#lights=(value) ⇒ <StoplightAdmin::LightsRepository::Light>



12
13
14
# File 'lib/stoplight_admin/lights_stats.rb', line 12

def lights
  @lights
end

Class Method Details

.call(lights) ⇒ Object



16
17
18
# File 'lib/stoplight_admin/lights_stats.rb', line 16

def call(lights)
  new(lights).call
end

Instance Method Details

#callObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/stoplight_admin/lights_stats.rb', line 26

def call
  return EMPTY_STATS if size.zero?

  EMPTY_STATS.merge(
    count_red: count_red,
    count_yellow: count_yellow,
    count_green: count_green,
    percent_red: percent_red,
    percent_yellow: percent_yellow,
    percent_green: percent_green
  )
end