Class: Miu::Messages::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/miu/messages/base.rb

Direct Known Subclasses

Enter, Leave, Text, Unknown

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Base

Returns a new instance of Base.

Yields:

  • (_self)

Yield Parameters:



11
12
13
14
15
16
17
18
# File 'lib/miu/messages/base.rb', line 11

def initialize(options = {})
  @id = options[:id] || SecureRandom.uuid
  @time = options[:time] || Time.now.to_i
  @network = Miu::Utility.adapt(Resources::Network, options[:network] || {})
  @type = options[:type]
  @content = options[:content]
  yield self if block_given?
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



9
10
11
# File 'lib/miu/messages/base.rb', line 9

def content
  @content
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/miu/messages/base.rb', line 8

def id
  @id
end

#networkObject

Returns the value of attribute network.



9
10
11
# File 'lib/miu/messages/base.rb', line 9

def network
  @network
end

#timeObject

Returns the value of attribute time.



8
9
10
# File 'lib/miu/messages/base.rb', line 8

def time
  @time
end

#typeObject

Returns the value of attribute type.



9
10
11
# File 'lib/miu/messages/base.rb', line 9

def type
  @type
end

Instance Method Details

#to_hObject



20
21
22
23
24
25
26
27
28
# File 'lib/miu/messages/base.rb', line 20

def to_h
  {
    :id => @id,
    :time => @time,
    :network => @network.to_h,
    :type => @type,
    :content => @content ? @content.to_h : {}
  }
end

#to_msgpack(*args) ⇒ Object



30
31
32
# File 'lib/miu/messages/base.rb', line 30

def to_msgpack(*args)
  to_h.to_msgpack(*args)
end