Class: CIAT::TrafficLight

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(setting = :unset) ⇒ TrafficLight

:nodoc:



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

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

Instance Attribute Details

#settingObject (readonly)

Returns the value of attribute setting.



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

def setting
  @setting
end

Instance Method Details

#colorObject



36
37
38
# File 'lib/ciat/traffic_light.rb', line 36

def color
  @setting.to_s
end

#green!Object

:nodoc:



16
17
18
# File 'lib/ciat/traffic_light.rb', line 16

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

#green?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/ciat/traffic_light.rb', line 12

def green?
  @setting == :green
end

#red!Object

:nodoc:



32
33
34
# File 'lib/ciat/traffic_light.rb', line 32

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

#red?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/ciat/traffic_light.rb', line 28

def red?
  @setting == :red
end

#unset?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/ciat/traffic_light.rb', line 8

def unset?
  @setting == :unset
end

#yellow!Object

:nodoc:



24
25
26
# File 'lib/ciat/traffic_light.rb', line 24

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

#yellow?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/ciat/traffic_light.rb', line 20

def yellow?
  @setting == :yellow
end