Class: Lwes::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/lwes/event.rb

Overview

Represent a LWES event, can read from and write to IO objects

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Event

Creates a new Lwes::Emitter.

Parameters:

  • hash (Hash) (defaults to: {})

Options Hash (hash):

  • :name (String)

    The event name

  • :attributes (Hash)

    Attributes of the event. The hash key is the attribute name, the hash value should be an Array of two elements. The first element is the type see TYPE_TO_BYTE for all available types. The second element is the actual value of the attribute.

  • :address_family, (Number)

    Address family of the socket, defaults to Socket::AF_INET.



19
20
21
22
# File 'lib/lwes/event.rb', line 19

def initialize(hash={})
  self.name = hash[:name] || ""
  self.attributes = hash[:attributes] || {}
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



9
10
11
# File 'lib/lwes/event.rb', line 9

def attributes
  @attributes
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/lwes/event.rb', line 9

def name
  @name
end

Class Method Details

.read(io) ⇒ Lwes::Event

Read from an IO object

Parameters:

  • io (IO)

    The IO object to read from.

Returns:



41
42
43
44
45
# File 'lib/lwes/event.rb', line 41

def self.read(io)
  event = new
  event.read(io)
  event
end

Instance Method Details

#read(io) ⇒ Object

Read from an IO object

Parameters:

  • io (IO)

    The IO object to read from.



33
34
35
36
# File 'lib/lwes/event.rb', line 33

def read(io)
  serializer = Lwes::Serialization::Event.read(io)
  set_attributes_from_serializer(serializer)
end

#to_hashHash

Converts the event to a hash representation

Returns:

  • (Hash)

    the hash representation of the instance.



49
50
51
52
53
54
# File 'lib/lwes/event.rb', line 49

def to_hash
  {
    :name => name,
    :attributes => attributes
  }
end

#write(io) ⇒ Number

Writes the event to an IO object

Parameters:

  • io (IO)

    The IO object to write to.

Returns:

  • (Number)

    Number of bytes written to IO



27
28
29
# File 'lib/lwes/event.rb', line 27

def write(io)
  serializer.write(io)
end