class RapidsRivers::Packet

Understands a specifc message

Constants

CONTRIBUTING_SERVICES
VISIT_COUNT

The following keys are reserved for system usage:

Attributes

contributing_services[R]
system_read_count[R]

Public Class Methods

new(json_hash) click to toggle source
# File lib/rapids_rivers/packet.rb, line 14
def initialize(json_hash)
  @json_hash = json_hash
  @system_read_count = (@json_hash[VISIT_COUNT] || -1) + 1
  @contributing_services = @json_hash[CONTRIBUTING_SERVICES] || []
  @used_keys = [VISIT_COUNT, CONTRIBUTING_SERVICES]
end

Public Instance Methods

clone_with_name(service_name) click to toggle source
# File lib/rapids_rivers/packet.rb, line 25
def clone_with_name(service_name)
  self.clone.tap { |packet_copy| packet_copy.contributing_services << service_name }
end
pretty_print() click to toggle source
# File lib/rapids_rivers/packet.rb, line 38
def pretty_print
  update_hash
  JSON.pretty_generate @json_hash
end
to_json() click to toggle source
# File lib/rapids_rivers/packet.rb, line 29
def to_json
  update_hash
  @json_hash.to_json
end
to_s() click to toggle source
# File lib/rapids_rivers/packet.rb, line 34
def to_s
  "Packet (in JSON): #{self.to_json}"
end
used_key(key) click to toggle source
# File lib/rapids_rivers/packet.rb, line 21
def used_key(key)
  @used_keys << key.to_s
end

Private Instance Methods

update_hash() click to toggle source
# File lib/rapids_rivers/packet.rb, line 45
def update_hash
  @used_keys.each do |key|
    value = instance_variable_get("@#{key}".to_sym)
    @json_hash[key] = value if value
  end
end