Class: NchanTools::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.



221
222
223
# File 'lib/nchan_tools/pubsub.rb', line 221

def initialize
  @log = []
end

Instance Method Details

#filter(opt) ⇒ Object



229
230
231
232
233
234
235
236
237
# File 'lib/nchan_tools/pubsub.rb', line 229

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



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

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

#showObject



239
240
241
# File 'lib/nchan_tools/pubsub.rb', line 239

def show
  @log
end

#to_sObject



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

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