Class: Cosmos::PacketItemLimits

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializePacketItemLimits

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

#enabledBoolean

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.

Returns:

  • (Boolean)

    Whether limits are enabled on this item



37
38
39
# File 'lib/cosmos/packets/packet_item_limits.rb', line 37

def enabled
  @enabled
end

#persistence_countInteger

Current persistent count. The count will be reset to zero if the limits state hasn’t changed (i.e. remained :GREEN).

Returns:

  • (Integer)

    Current running persistence count



57
58
59
# File 'lib/cosmos/packets/packet_item_limits.rb', line 57

def persistence_count
  @persistence_count
end

#persistence_settingInteger

Returns Number of out of limits samples at which the limits state will change.

Returns:

  • (Integer)

    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

#responseLimitsResponse

Returns Response method to be called on limits changes.

Returns:



48
49
50
# File 'lib/cosmos/packets/packet_item_limits.rb', line 48

def response
  @response
end

#stateSymbol?

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.

Returns:

  • (Symbol, nil)

    Current limits state of the item



45
46
47
# File 'lib/cosmos/packets/packet_item_limits.rb', line 45

def state
  @state
end

#valuesHash{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)].

Returns:

  • (Hash{Symbol=>Array})

    Hash of all the limits defined for this item. Must include a hash key of :DEFAULT which returns the default limits.



30
31
32
# File 'lib/cosmos/packets/packet_item_limits.rb', line 30

def values
  @values
end

Instance Method Details

#cloneObject 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_hashObject



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