Class: StoplightAdmin::LightsRepository::Light
- Inherits:
-
Object
- Object
- StoplightAdmin::LightsRepository::Light
- Defined in:
- lib/stoplight_admin/lights_repository/light.rb
Constant Summary collapse
- COLORS =
[ GREEN = Stoplight::Color::GREEN, YELLOW = Stoplight::Color::YELLOW, RED = Stoplight::Color::RED ].freeze
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#failures ⇒ Object
Returns the value of attribute failures.
-
#name ⇒ Object
Returns the value of attribute name.
-
#state ⇒ Object
Returns the value of attribute state.
Instance Method Summary collapse
- #as_json ⇒ Object
- #default_sort_key ⇒ Array
-
#initialize(name:, color:, state:, failures:) ⇒ Light
constructor
A new instance of Light.
- #locked? ⇒ Boolean
- #unlocked? ⇒ Boolean
Constructor Details
#initialize(name:, color:, state:, failures:) ⇒ Light
Returns a new instance of Light.
32 33 34 35 36 37 |
# File 'lib/stoplight_admin/lights_repository/light.rb', line 32 def initialize(name:, color:, state:, failures:) @name = name @color = color @state = state @failures = failures end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
18 19 20 |
# File 'lib/stoplight_admin/lights_repository/light.rb', line 18 def color @color end |
#failures ⇒ Object
Returns the value of attribute failures.
26 27 28 |
# File 'lib/stoplight_admin/lights_repository/light.rb', line 26 def failures @failures end |
#name ⇒ Object
Returns the value of attribute name.
14 15 16 |
# File 'lib/stoplight_admin/lights_repository/light.rb', line 14 def name @name end |
#state ⇒ Object
Returns the value of attribute state.
22 23 24 |
# File 'lib/stoplight_admin/lights_repository/light.rb', line 22 def state @state end |
Instance Method Details
#as_json ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/stoplight_admin/lights_repository/light.rb', line 49 def as_json { name: name, color: color, failures: failures, locked: locked? } end |
#default_sort_key ⇒ Array
59 60 61 |
# File 'lib/stoplight_admin/lights_repository/light.rb', line 59 def default_sort_key [-COLORS.index(color), name] end |
#locked? ⇒ Boolean
40 41 42 |
# File 'lib/stoplight_admin/lights_repository/light.rb', line 40 def locked? !unlocked? end |
#unlocked? ⇒ Boolean
45 46 47 |
# File 'lib/stoplight_admin/lights_repository/light.rb', line 45 def unlocked? state == Stoplight::State::UNLOCKED end |