Class: RSMP::TLC::SignalPriority
- Inherits:
-
Object
- Object
- RSMP::TLC::SignalPriority
- Defined in:
- lib/rsmp/tlc/signal_priority.rb
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.
6 7 8 9 10 11 12 13 |
# File 'lib/rsmp/tlc/signal_priority.rb', line 6 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.
4 5 6 |
# File 'lib/rsmp/tlc/signal_priority.rb', line 4 def age @age end |
#eta ⇒ Object (readonly)
Returns the value of attribute eta.
4 5 6 |
# File 'lib/rsmp/tlc/signal_priority.rb', line 4 def eta @eta end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/rsmp/tlc/signal_priority.rb', line 4 def id @id end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
4 5 6 |
# File 'lib/rsmp/tlc/signal_priority.rb', line 4 def level @level end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
4 5 6 |
# File 'lib/rsmp/tlc/signal_priority.rb', line 4 def node @node end |
#state ⇒ Object
Returns the value of attribute state.
4 5 6 |
# File 'lib/rsmp/tlc/signal_priority.rb', line 4 def state @state end |
#updated ⇒ Object (readonly)
Returns the value of attribute updated.
4 5 6 |
# File 'lib/rsmp/tlc/signal_priority.rb', line 4 def updated @updated end |
#vehicle_type ⇒ Object (readonly)
Returns the value of attribute vehicle_type.
4 5 6 |
# File 'lib/rsmp/tlc/signal_priority.rb', line 4 def vehicle_type @vehicle_type end |
Instance Method Details
#cancel ⇒ Object
19 20 21 22 23 |
# File 'lib/rsmp/tlc/signal_priority.rb', line 19 def cancel return unless @state == 'activated' self.state = 'completed' end |
#prune? ⇒ Boolean
15 16 17 |
# File 'lib/rsmp/tlc/signal_priority.rb', line 15 def prune? @state == 'stale' || @state == 'completed' end |
#timer ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rsmp/tlc/signal_priority.rb', line 31 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 |