Class: CIAT::TrafficLight

Inherits:
Object
  • Object
show all
Defined in:
lib/ciat/traffic_light.rb

Constant Summary collapse

GREEN =
CIAT::TrafficLight.new(:green)
RED =
CIAT::TrafficLight.new(:red)
YELLOW =
CIAT::TrafficLight.new(:yellow)
UNSET =
CIAT::TrafficLight.new(:unset)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(setting = :unset) ⇒ TrafficLight

:nodoc:



5
6
7
# File 'lib/ciat/traffic_light.rb', line 5

def initialize(setting = :unset) #:nodoc:
  @setting = setting
end

Instance Attribute Details

#settingObject (readonly)

Returns the value of attribute setting.



3
4
5
# File 'lib/ciat/traffic_light.rb', line 3

def setting
  @setting
end

Instance Method Details

#colorObject



42
43
44
# File 'lib/ciat/traffic_light.rb', line 42

def color
  @setting.to_s
end

#green!Object

:nodoc:



22
23
24
# File 'lib/ciat/traffic_light.rb', line 22

def green! #:nodoc:
  @setting = :green unless yellow?
end

#green?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/ciat/traffic_light.rb', line 18

def green?
  @setting == :green
end

#red!Object

:nodoc:



38
39
40
# File 'lib/ciat/traffic_light.rb', line 38

def red! #:nodoc:
  @setting = :red unless yellow?
end

#red?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/ciat/traffic_light.rb', line 34

def red?
  @setting == :red
end

#unset?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/ciat/traffic_light.rb', line 14

def unset?
  @setting == :unset
end

#yellow!Object

:nodoc:



30
31
32
# File 'lib/ciat/traffic_light.rb', line 30

def yellow! #:nodoc:
  @setting = :yellow
end

#yellow?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/ciat/traffic_light.rb', line 26

def yellow?
  @setting == :yellow
end