Class: Miu::Messages::Base
- Inherits:
-
Object
- Object
- Miu::Messages::Base
- Defined in:
- lib/miu/messages/base.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#id ⇒ Object
Returns the value of attribute id.
-
#network ⇒ Object
Returns the value of attribute network.
-
#time ⇒ Object
Returns the value of attribute time.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(options = {}) {|_self| ... } ⇒ Base
constructor
A new instance of Base.
- #to_h ⇒ Object
- #to_msgpack(*args) ⇒ Object
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Base
Returns a new instance of Base.
11 12 13 14 15 16 17 18 |
# File 'lib/miu/messages/base.rb', line 11 def initialize( = {}) @id = [:id] || SecureRandom.uuid @time = [:time] || Time.now.to_i @network = Miu::Utility.adapt(Resources::Network, [:network] || {}) @type = [:type] @content = [:content] yield self if block_given? end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
9 10 11 |
# File 'lib/miu/messages/base.rb', line 9 def content @content end |
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/miu/messages/base.rb', line 8 def id @id end |
#network ⇒ Object
Returns the value of attribute network.
9 10 11 |
# File 'lib/miu/messages/base.rb', line 9 def network @network end |
#time ⇒ Object
Returns the value of attribute time.
8 9 10 |
# File 'lib/miu/messages/base.rb', line 8 def time @time end |
#type ⇒ Object
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_h ⇒ Object
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 |