Class: Subscriber::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/nchan_tools/pubsub.rb

Instance Method Summary collapse

Constructor Details

#initializeLogger

Returns a new instance of Logger.



224
225
226
# File 'lib/nchan_tools/pubsub.rb', line 224

def initialize
  @log = []
end

Instance Method Details

#filter(opt) ⇒ Object



232
233
234
235
236
237
238
239
240
# File 'lib/nchan_tools/pubsub.rb', line 232

def filter(opt)
  opt[:id] = opt[:id].to_sym if opt[:id]
  opt[:type] = opt[:type].to_sym if opt[:type]
  @log.select do |l|
    true unless ((opt[:id] && opt[:id] != l[:id]) ||
                 (opt[:type] && opt[:type] != l[:type]) ||
                 (opt[:data] && !l.match(opt[:data])))
  end
end

#log(id, type, msg = nil) ⇒ Object



228
229
230
# File 'lib/nchan_tools/pubsub.rb', line 228

def log(id, type, msg=nil)
  @log << {time: Time.now.to_f.round(4), id: id.to_sym, type: type, data: msg}
end

#showObject



242
243
244
# File 'lib/nchan_tools/pubsub.rb', line 242

def show
  @log
end

#to_sObject



246
247
248
# File 'lib/nchan_tools/pubsub.rb', line 246

def to_s
  @log.map {|l| "#{l.id} (#{l.type}) #{msg.to_s}"}.join "\n"
end