Class: RSMP::TLC::SignalPlan

Inherits:
Object
  • Object
show all
Defined in:
lib/rsmp/tlc/signal_plan.rb

Overview

A Traffic Light Controller Signal Plan. A signal plan is a description of how all signal groups should change state over time.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nr:, cycle_time:, states:, dynamic_bands:) ⇒ SignalPlan

Returns a new instance of SignalPlan.



8
9
10
11
12
13
# File 'lib/rsmp/tlc/signal_plan.rb', line 8

def initialize nr:, cycle_time:, states:, dynamic_bands:
  @nr = nr
  @states = states
  @dynamic_bands = dynamic_bands || {}
  @cycle_time = cycle_time
end

Instance Attribute Details

#cycle_timeObject (readonly)

Returns the value of attribute cycle_time.



7
8
9
# File 'lib/rsmp/tlc/signal_plan.rb', line 7

def cycle_time
  @cycle_time
end

#dynamic_bandsObject (readonly)

Returns the value of attribute dynamic_bands.



7
8
9
# File 'lib/rsmp/tlc/signal_plan.rb', line 7

def dynamic_bands
  @dynamic_bands
end

#nrObject (readonly)

Returns the value of attribute nr.



7
8
9
# File 'lib/rsmp/tlc/signal_plan.rb', line 7

def nr
  @nr
end

#statesObject (readonly)

Returns the value of attribute states.



7
8
9
# File 'lib/rsmp/tlc/signal_plan.rb', line 7

def states
  @states
end

Instance Method Details

#dynamic_bands_stringObject



15
16
17
18
19
# File 'lib/rsmp/tlc/signal_plan.rb', line 15

def dynamic_bands_string
  str = @dynamic_bands.map { |band,value| "#{nr}-#{band}-#{value}" }.join(',')
  return nil if str == ''
  str
end

#get_band(band) ⇒ Object



25
26
27
# File 'lib/rsmp/tlc/signal_plan.rb', line 25

def get_band band
  @dynamic_bands[ band.to_i ]
end

#set_band(band, value) ⇒ Object



21
22
23
# File 'lib/rsmp/tlc/signal_plan.rb', line 21

def set_band band, value
  @dynamic_bands[ band.to_i ] = value.to_i
end

#set_cycle_time(cycle_time) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
32
# File 'lib/rsmp/tlc/signal_plan.rb', line 29

def set_cycle_time cycle_time
  raise ArgumentError if cycle_time < 0
  @cycle_time = cycle_time
end