Class: NchanTools::Subscriber::Logger
- Inherits:
-
Object
- Object
- NchanTools::Subscriber::Logger
- Defined in:
- lib/nchan_tools/pubsub.rb
Instance Method Summary collapse
- #filter(opt) ⇒ Object
-
#initialize ⇒ Logger
constructor
A new instance of Logger.
- #log(id, type, msg = nil) ⇒ Object
- #show ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Logger
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 |
#show ⇒ Object
239 240 241 |
# File 'lib/nchan_tools/pubsub.rb', line 239 def show @log end |
#to_s ⇒ Object
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 |