Class: QQQ::Event
- Inherits:
-
Object
- Object
- QQQ::Event
- Defined in:
- lib/qqq/events.rb
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#recorded_at ⇒ Object
readonly
Returns the value of attribute recorded_at.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #for_humans ⇒ Object
-
#initialize(uuid:, message:, recorded_at:) ⇒ Event
constructor
A new instance of Event.
- #to_json(*options) ⇒ Object
Constructor Details
#initialize(uuid:, message:, recorded_at:) ⇒ Event
Returns a new instance of Event.
17 18 19 20 21 |
# File 'lib/qqq/events.rb', line 17 def initialize(uuid:, message:, recorded_at:) @uuid = uuid @recorded_at = recorded_at = end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
4 5 6 |
# File 'lib/qqq/events.rb', line 4 def end |
#recorded_at ⇒ Object (readonly)
Returns the value of attribute recorded_at.
4 5 6 |
# File 'lib/qqq/events.rb', line 4 def recorded_at @recorded_at end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
4 5 6 |
# File 'lib/qqq/events.rb', line 4 def uuid @uuid end |
Class Method Details
.from_json_string(json_string) ⇒ Object
12 13 14 15 |
# File 'lib/qqq/events.rb', line 12 def self.from_json_string(json_string) payload = JSON.parse json_string Event.new(uuid: payload["uuid"], message: payload["message"], recorded_at: payload["recorded_at"]) end |
.from_message(message) ⇒ Object
6 7 8 9 10 |
# File 'lib/qqq/events.rb', line 6 def self.() = Time.now uuid = UUIDTools::UUID.random_create().to_s Event.new(uuid: uuid, message: , recorded_at: ) end |
Instance Method Details
#as_json(options = {}) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/qqq/events.rb', line 27 def as_json(={}) { uuid: @uuid, message: , recorded_at: @recorded_at, } end |
#for_humans ⇒ Object
23 24 25 |
# File 'lib/qqq/events.rb', line 23 def for_humans "[#{@uuid}] [#{@recorded_at}] #{@message}" end |
#to_json(*options) ⇒ Object
34 35 36 |
# File 'lib/qqq/events.rb', line 34 def to_json(*) as_json(*).to_json(*) end |