Class: FluQ::Event

Inherits:
Hash
  • Object
show all
Defined in:
lib/fluq/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag = "", timestamp = 0, record = {}) ⇒ Event

Returns a new instance of Event.

Parameters:

  • tag (String) (defaults to: "")

    the event tag

  • timestamp (Integer) (defaults to: 0)

    the UNIX timestamp

  • record (Hash) (defaults to: {})

    the attribute pairs



8
9
10
11
12
# File 'lib/fluq/event.rb', line 8

def initialize(tag = "", timestamp = 0, record = {})
  @tag, @timestamp = tag.to_s, timestamp.to_i
  super()
  update(record) if Hash === record
end

Instance Attribute Details

#tagObject (readonly)

Returns the value of attribute tag.



3
4
5
# File 'lib/fluq/event.rb', line 3

def tag
  @tag
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



3
4
5
# File 'lib/fluq/event.rb', line 3

def timestamp
  @timestamp
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Returns true if comparable.

Returns:

  • (Boolean)

    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

#inspectString

Returns inspection.

Returns:

  • (String)

    inspection



51
52
53
# File 'lib/fluq/event.rb', line 51

def inspect
  [tag, timestamp, Hash.new.update(self)].inspect
end

#timeTime

Returns UTC time.

Returns:

  • (Time)

    UTC time



15
16
17
# File 'lib/fluq/event.rb', line 15

def time
  @time ||= Time.at(timestamp).utc
end

#to_aArray

Returns tuple.

Returns:

  • (Array)

    tuple



20
21
22
# File 'lib/fluq/event.rb', line 20

def to_a
  [tag, timestamp, self]
end

#to_jsonString

Returns JSON encoded.

Returns:

  • (String)

    JSON encoded



41
42
43
# File 'lib/fluq/event.rb', line 41

def to_json
  Oj.dump merge("=" => tag, "@" => timestamp)
end

#to_msgpackString

Returns mgspack encoded bytes.

Returns:

  • (String)

    mgspack encoded bytes



46
47
48
# File 'lib/fluq/event.rb', line 46

def to_msgpack
  MessagePack.pack merge("=" => tag, "@" => timestamp)
end

#to_tsvString

Returns tab-separated string.

Returns:

  • (String)

    tab-separated string



36
37
38
# File 'lib/fluq/event.rb', line 36

def to_tsv
  [tag, timestamp, Oj.dump(self)].join("\t")
end