Class: DmmUtil::Cursor

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

Instance Method Summary collapse

Constructor Details

#initialize(driver, count_name, query_func, klass) ⇒ Cursor

Returns a new instance of Cursor.



5
6
7
8
9
10
# File 'lib/dmm_util/cursor.rb', line 5

def initialize(driver, count_name, query_func, klass)
  @driver = driver
  @count_name = count_name
  @query_func = query_func
  @klass = klass
end

Instance Method Details

#[](idx) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/dmm_util/cursor.rb', line 22

def [](idx)
  if @klass.instance_method(:initialize).arity == 2
     @klass.new(@driver, @driver.send(@query_func, idx))
  else
    @klass.new(@driver.send(@query_func, idx))
  end
end

#countObject



12
13
14
# File 'lib/dmm_util/cursor.rb', line 12

def count
  @count = @count || @driver.qsls[@count_name]
end

#eachObject



16
17
18
19
20
# File 'lib/dmm_util/cursor.rb', line 16

def each
  (0..(count-1)).each do |idx|
    yield(self[idx])
  end
end