class Irc::Bot::Journal::JournalMessage
Attributes
id[R]
a unique identification of this message
payload[R]
contains the actual message as a Hash
timestamp[R]
when this message was published as a Time instance
topic[R]
describes a hierarchical queue into which this message belongs
Public Class Methods
create(topic, payload, opt={})
click to toggle source
# File lib/rbot/journal.rb, line 79 def self.create(topic, payload, opt={}) # cleanup payload to only contain strings JournalMessage.new( id: opt[:id] || SecureRandom.uuid, timestamp: opt[:timestamp] || Time.now, topic: topic, payload: payload ) end
new(message)
click to toggle source
# File lib/rbot/journal.rb, line 45 def initialize(message) @id = message[:id] @timestamp = message[:timestamp] @topic = message[:topic] @payload = message[:payload] if @payload.class != Hash raise InvalidJournalMessage.new('payload must be a hash!') end end
Public Instance Methods
==(other)
click to toggle source
# File lib/rbot/journal.rb, line 75 def ==(other) (@id == other.id) rescue false end
[](key)
click to toggle source
Access payload value by key alias for get(key, nil).
# File lib/rbot/journal.rb, line 71 def [](key) get(key, nil) end
get(pkey, default=:exception)
click to toggle source
Access payload value by key.
# File lib/rbot/journal.rb, line 56 def get(pkey, default=:exception) # IDENTITY = Object.new instead of :ex..? value = pkey.split('.').reduce(@payload) do |hash, key| if hash.has_key?(key) or hash.has_key?(key.to_sym) hash[key] || hash[key.to_sym] else if default == :exception raise ArgumentError.new else default end end end end