Class: Skyfall::Jetstream::Message
- Inherits:
-
Object
- Object
- Skyfall::Jetstream::Message
- Defined in:
- lib/skyfall/jetstream/message.rb
Direct Known Subclasses
AccountMessage, CommitMessage, IdentityMessage, UnknownMessage
Instance Attribute Summary collapse
-
#did ⇒ Object
(also: #repo)
readonly
Returns the value of attribute did.
-
#json ⇒ Object
readonly
:nodoc: - consider this as semi-private API.
-
#time_us ⇒ Object
(also: #seq)
readonly
Returns the value of attribute time_us.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(json) ⇒ Message
constructor
A new instance of Message.
- #operations ⇒ Object
- #time ⇒ Object
Constructor Details
#initialize(json) ⇒ Message
Returns a new instance of Message.
35 36 37 38 39 40 |
# File 'lib/skyfall/jetstream/message.rb', line 35 def initialize(json) @json = json @type = @json['kind'].to_sym @did = @json['did'] @time_us = @json['time_us'] end |
Instance Attribute Details
#did ⇒ Object (readonly) Also known as: repo
Returns the value of attribute did.
13 14 15 |
# File 'lib/skyfall/jetstream/message.rb', line 13 def did @did end |
#json ⇒ Object (readonly)
:nodoc: - consider this as semi-private API
18 19 20 |
# File 'lib/skyfall/jetstream/message.rb', line 18 def json @json end |
#time_us ⇒ Object (readonly) Also known as: seq
Returns the value of attribute time_us.
13 14 15 |
# File 'lib/skyfall/jetstream/message.rb', line 13 def time_us @time_us end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
13 14 15 |
# File 'lib/skyfall/jetstream/message.rb', line 13 def type @type end |
Class Method Details
.new(data) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/skyfall/jetstream/message.rb', line 20 def self.new(data) json = JSON.parse(data) = case json['kind'] when 'account' then Jetstream::AccountMessage when 'commit' then Jetstream::CommitMessage when 'identity' then Jetstream::IdentityMessage else Jetstream::UnknownMessage end = .allocate .send(:initialize, json) end |
Instance Method Details
#operations ⇒ Object
42 43 44 |
# File 'lib/skyfall/jetstream/message.rb', line 42 def operations [] end |
#time ⇒ Object
46 47 48 |
# File 'lib/skyfall/jetstream/message.rb', line 46 def time @time ||= @json['time_us'] && Time.at(@json['time_us'] / 1_000_000.0) end |