Class: Subscriber::Logger
- Inherits:
-
Object
- Object
- 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.
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 |
#show ⇒ Object
242 243 244 |
# File 'lib/nchan_tools/pubsub.rb', line 242 def show @log end |
#to_s ⇒ Object
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 |