Class: FluQ::Event
- Inherits:
-
Hash
- Object
- Hash
- FluQ::Event
- Defined in:
- lib/fluq/event.rb
Instance Attribute Summary collapse
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
True if comparable.
-
#initialize(tag = "", timestamp = 0, record = {}) ⇒ Event
constructor
A new instance of Event.
-
#inspect ⇒ String
Inspection.
-
#time ⇒ Time
UTC time.
-
#to_a ⇒ Array
Tuple.
-
#to_json ⇒ String
JSON encoded.
-
#to_msgpack ⇒ String
Mgspack encoded bytes.
-
#to_tsv ⇒ String
Tab-separated string.
Constructor Details
#initialize(tag = "", timestamp = 0, record = {}) ⇒ Event
Returns a new instance of Event.
8 9 10 11 12 |
# File 'lib/fluq/event.rb', line 8 def initialize(tag = "", = 0, record = {}) @tag, @timestamp = tag.to_s, .to_i super() update(record) if Hash === record end |
Instance Attribute Details
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
3 4 5 |
# File 'lib/fluq/event.rb', line 3 def tag @tag end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
3 4 5 |
# File 'lib/fluq/event.rb', line 3 def @timestamp end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Returns true if comparable.
25 26 27 28 29 30 31 32 |
# File 'lib/fluq/event.rb', line 25 def ==(other) case other when Array to_a == other else super end end |
#inspect ⇒ String
Returns inspection.
51 52 53 |
# File 'lib/fluq/event.rb', line 51 def inspect [tag, , Hash.new.update(self)].inspect end |
#time ⇒ Time
Returns UTC time.
15 16 17 |
# File 'lib/fluq/event.rb', line 15 def time @time ||= Time.at().utc end |
#to_a ⇒ Array
Returns tuple.
20 21 22 |
# File 'lib/fluq/event.rb', line 20 def to_a [tag, , self] end |
#to_json ⇒ String
Returns JSON encoded.
41 42 43 |
# File 'lib/fluq/event.rb', line 41 def to_json Oj.dump merge("=" => tag, "@" => ) end |
#to_msgpack ⇒ String
Returns mgspack encoded bytes.
46 47 48 |
# File 'lib/fluq/event.rb', line 46 def to_msgpack MessagePack.pack merge("=" => tag, "@" => ) end |
#to_tsv ⇒ String
Returns tab-separated string.
36 37 38 |
# File 'lib/fluq/event.rb', line 36 def to_tsv [tag, , Oj.dump(self)].join("\t") end |