Class: Logn::Events

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/logn.rb

Instance Method Summary collapse

Constructor Details

#initializeEvents

Returns a new instance of Events.



36
37
38
39
# File 'lib/logn.rb', line 36

def initialize
  @events  = []
  @filters = []
end

Instance Method Details

#add(event) ⇒ Object



41
42
43
# File 'lib/logn.rb', line 41

def add(event)
  @events << event
end

#add_filter(&block) ⇒ Object



45
46
47
# File 'lib/logn.rb', line 45

def add_filter &block
  @filters << block
end

#each(*args, &block) ⇒ Object



55
56
57
# File 'lib/logn.rb', line 55

def each(*args, &block)
  matching.each(*args, &block)
end

#matchingObject



49
50
51
52
53
# File 'lib/logn.rb', line 49

def matching
  @events.select do |event|
    @filters.all? {|filter| filter.call event }
  end
end

#sizeObject



59
60
61
62
# File 'lib/logn.rb', line 59

def size
  return @events.size if @filters.empty?
  matching.size
end