Class: RSMP::TLC::SignalPriority
- Inherits:
-
Object
- Object
- RSMP::TLC::SignalPriority
- Defined in:
- lib/rsmp/tlc/signal_priority.rb
Overview
Representation of a priority request for a TLC signal.
Instance Attribute Summary collapse
-
#age ⇒ Object
readonly
Returns the value of attribute age.
-
#eta ⇒ Object
readonly
Returns the value of attribute eta.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#state ⇒ Object
Returns the value of attribute state.
-
#updated ⇒ Object
readonly
Returns the value of attribute updated.
-
#vehicle_type ⇒ Object
readonly
Returns the value of attribute vehicle_type.
Instance Method Summary collapse
- #cancel ⇒ Object
-
#initialize(node:, id:, level:, eta:, vehicle_type:) ⇒ SignalPriority
constructor
A new instance of SignalPriority.
- #prune? ⇒ Boolean
- #timer ⇒ Object
Constructor Details
#initialize(node:, id:, level:, eta:, vehicle_type:) ⇒ SignalPriority
Returns a new instance of SignalPriority.
7 8 9 10 11 12 13 14 |
# File 'lib/rsmp/tlc/signal_priority.rb', line 7 def initialize(node:, id:, level:, eta:, vehicle_type:) @node = node @id = id @level = level @eta = eta @vehicle_type = vehicle_type self.state = 'received' end |
Instance Attribute Details
#age ⇒ Object (readonly)
Returns the value of attribute age.
5 6 7 |
# File 'lib/rsmp/tlc/signal_priority.rb', line 5 def age @age end |
#eta ⇒ Object (readonly)
Returns the value of attribute eta.
5 6 7 |
# File 'lib/rsmp/tlc/signal_priority.rb', line 5 def eta @eta end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/rsmp/tlc/signal_priority.rb', line 5 def id @id end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
5 6 7 |
# File 'lib/rsmp/tlc/signal_priority.rb', line 5 def level @level end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
5 6 7 |
# File 'lib/rsmp/tlc/signal_priority.rb', line 5 def node @node end |
#state ⇒ Object
Returns the value of attribute state.
5 6 7 |
# File 'lib/rsmp/tlc/signal_priority.rb', line 5 def state @state end |
#updated ⇒ Object (readonly)
Returns the value of attribute updated.
5 6 7 |
# File 'lib/rsmp/tlc/signal_priority.rb', line 5 def updated @updated end |
#vehicle_type ⇒ Object (readonly)
Returns the value of attribute vehicle_type.
5 6 7 |
# File 'lib/rsmp/tlc/signal_priority.rb', line 5 def vehicle_type @vehicle_type end |
Instance Method Details
#cancel ⇒ Object
20 21 22 23 24 |
# File 'lib/rsmp/tlc/signal_priority.rb', line 20 def cancel return unless @state == 'activated' self.state = 'completed' end |
#prune? ⇒ Boolean
16 17 18 |
# File 'lib/rsmp/tlc/signal_priority.rb', line 16 def prune? @state == 'stale' || @state == 'completed' end |
#timer ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rsmp/tlc/signal_priority.rb', line 32 def timer @age = @node.clock.now - @updated case @state when 'received' if @age >= 0.5 @node.log "Priority request #{@id} activated.", level: :info self.state = 'activated' end when 'activated' if @age >= 1 @node.log "Priority request #{@id} became stale.", level: :info self.state = 'stale' end end end |