Class: Packet

Inherits:
Object
  • Object
show all
Defined in:
lib/packet.rb,
lib/cron_feeder.rb

Overview

this is an abstract packet class that knows how to marshal itself into and out of JSON format

Instance Method Summary collapse

Constructor Details

#initializePacket

Returns a new instance of Packet.

Raises:

  • (NotImplementedError)


6
7
8
# File 'lib/packet.rb', line 6

def initialize
  raise NotImplementedError.new("#{self.class.name} is an abstract class.")
end

Instance Method Details

#to_json(*a) ⇒ Object



9
10
11
12
13
14
# File 'lib/packet.rb', line 9

def to_json(*a)
  {
    'json_class'   => self.class.name,
    'data'         => instance_variables.inject({}) {|m,ivar| m[ivar.sub(/@/,'')] = instance_variable_get(ivar); m }
  }.to_json(*a)
end