Class: Traildb::TrailDBCursor

Inherits:
FFI::AutoPointer
  • Object
show all
Includes:
Enumerable
Defined in:
lib/traildb.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cursor, cls, valuefun, parsetime, only_timestamp, event_filter_obj) ⇒ TrailDBCursor

Returns a new instance of TrailDBCursor.



183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/traildb.rb', line 183

def initialize(cursor, cls, valuefun, parsetime, only_timestamp, event_filter_obj)
  super cursor
  @cls = cls
  @valuefun = valuefun
  @parsetime = parsetime
  @only_timestamp = only_timestamp
  if event_filter_obj
    @event_filter_obj = event_filter_obj
    ret = Traildb.tdb_cursor_set_event_filter(self, event_filter_obj)
    raise TrailDBError.new("cursor_set_event_filter failed", ret) if ret != 0
  end
end

Class Method Details

.release(ptr) ⇒ Object



211
212
213
# File 'lib/traildb.rb', line 211

def self.release(ptr)
  Trailsdb.tdb_cursor_free(ptr)
end

Instance Method Details

#eachObject



196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/traildb.rb', line 196

def each
  loop do
    event = Traildb.tdb_cursor_next(self)
    break if event.null?
    timestamp = event[:timestamp]
    timestamp = Time.at(timestamp) if @parsetime
    if @only_timestamp
      yield timestamp
    else
      items = event.tdb_items(@valuefun)
      yield @cls.new(timestamp, *items)
    end
  end
end