Class: Logn::Events
Instance Method Summary collapse
- #add(event) ⇒ Object
- #add_filter(&block) ⇒ Object
- #each(*args, &block) ⇒ Object
-
#initialize ⇒ Events
constructor
A new instance of Events.
- #matching ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize ⇒ Events
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 |
#matching ⇒ Object
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 |
#size ⇒ Object
59 60 61 62 |
# File 'lib/logn.rb', line 59 def size return @events.size if @filters.empty? matching.size end |