Class: Stoplight::Admin::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.



23
24
25
# File 'lib/stoplight/admin/lights_stats.rb', line 23

def initialize(lights)
  @lights = lights
end

Instance Attribute Details

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



13
14
15
# File 'lib/stoplight/admin/lights_stats.rb', line 13

def lights
  @lights
end

Class Method Details

.call(lights) ⇒ Object



17
18
19
# File 'lib/stoplight/admin/lights_stats.rb', line 17

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

Instance Method Details

#callObject



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

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