Class: Cosmos::PacketItemLimits
- Defined in:
- lib/cosmos/packets/packet_item_limits.rb
Overview
Maintains knowledge of limits for a PacketItem
Constant Summary collapse
- LIMITS_STATES =
Array of all limit states
[:RED, :RED_HIGH, :RED_LOW, :YELLOW, :YELLOW_HIGH, :YELLOW_LOW, :GREEN, :GREEN_HIGH, :GREEN_LOW, :BLUE, :STALE, nil]
- OUT_OF_LIMITS_STATES =
Array of all limit states which should be considered in error
[:RED, :RED_HIGH, :RED_LOW, :YELLOW, :YELLOW_HIGH, :YELLOW_LOW]
Instance Attribute Summary collapse
-
#enabled ⇒ Boolean
Every item effectively always has “limits” enabled because it can go from :STALE to nil as needed.
-
#persistence_count ⇒ Integer
Current persistent count.
-
#persistence_setting ⇒ Integer
Number of out of limits samples at which the limits state will change.
-
#response ⇒ LimitsResponse
Response method to be called on limits changes.
-
#state ⇒ Symbol?
Current limits state of the item.
-
#values ⇒ Hash{Symbol=>Array}
Hash of arrays - Hash key is uppercase symbol designating limits set.
Instance Method Summary collapse
-
#clone ⇒ Object
(also: #dup)
Make a light weight clone of this limits.
-
#initialize ⇒ PacketItemLimits
constructor
Create a PacketItemLimits.
- #to_hash ⇒ Object
Constructor Details
#initialize ⇒ PacketItemLimits
Create a PacketItemLimits
60 61 62 63 64 65 66 67 |
# File 'lib/cosmos/packets/packet_item_limits.rb', line 60 def initialize @values = nil @enabled = false @state = :STALE @response = nil @persistence_setting = 1 @persistence_count = 0 end |
Instance Attribute Details
#enabled ⇒ Boolean
Every item effectively always has “limits” enabled because it can go from :STALE to nil as needed. This flag indicates whether an item with defined limit values can transition from nil to the various other states.
37 38 39 |
# File 'lib/cosmos/packets/packet_item_limits.rb', line 37 def enabled @enabled end |
#persistence_count ⇒ Integer
Current persistent count. The count will be reset to zero if the limits state hasn’t changed (i.e. remained :GREEN).
57 58 59 |
# File 'lib/cosmos/packets/packet_item_limits.rb', line 57 def persistence_count @persistence_count end |
#persistence_setting ⇒ Integer
Returns Number of out of limits samples at which the limits state will change.
52 53 54 |
# File 'lib/cosmos/packets/packet_item_limits.rb', line 52 def persistence_setting @persistence_setting end |
#response ⇒ LimitsResponse
Returns Response method to be called on limits changes.
48 49 50 |
# File 'lib/cosmos/packets/packet_item_limits.rb', line 48 def response @response end |
#state ⇒ Symbol?
Current limits state of the item. One of nil, :STALE, :BLUE, :GREEN, :GREEN_HIGH, :GREEN_LOW, :YELLOW, :YELLOW_HIGH, :YELLOW_LOW, :RED, :RED_HIGH, :RED_LOW. Items initialize to :STALE and change states as the item value changes. If the limits are disabled the state changes to nil. If a packet becomes stale the items state changes to :STALE.
45 46 47 |
# File 'lib/cosmos/packets/packet_item_limits.rb', line 45 def state @state end |
#values ⇒ Hash{Symbol=>Array}
Hash of arrays - Hash key is uppercase symbol designating limits set. :DEFAULT limits set is required if item has limits. nil indicates the item does not have limits. For defined limits, each array in the hash contains [:RED_LOW, :YELLOW_LOW, :YELLOW_HIGH, :RED_HIGH, :GREEN_LOW (optional), GREEN_HIGH (optional)].
30 31 32 |
# File 'lib/cosmos/packets/packet_item_limits.rb', line 30 def values @values end |
Instance Method Details
#clone ⇒ Object Also known as: dup
Make a light weight clone of this limits
104 105 106 107 108 109 |
# File 'lib/cosmos/packets/packet_item_limits.rb', line 104 def clone limits = super() limits.values = self.values.clone if self.values limits.response = self.response.clone if self.response limits end |
#to_hash ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/cosmos/packets/packet_item_limits.rb', line 112 def to_hash hash = {} hash['values'] = self.values hash['enabled'] = self.enabled hash['state'] = self.state if self.response hash['response'] = self.response.to_s else hash['response'] = nil end hash['persistence_setting'] = self.persistence_setting hash['persistence_count'] = self.persistence_count hash end |