Class: DmmUtil::Cursor
- Inherits:
-
Object
- Object
- DmmUtil::Cursor
- Includes:
- Enumerable
- Defined in:
- lib/dmm_util/cursor.rb
Instance Method Summary collapse
- #[](idx) ⇒ Object
- #count ⇒ Object
- #each ⇒ Object
-
#initialize(driver, count_name, query_func, klass) ⇒ Cursor
constructor
A new instance of Cursor.
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 |
#count ⇒ Object
12 13 14 |
# File 'lib/dmm_util/cursor.rb', line 12 def count @count = @count || @driver.qsls[@count_name] end |
#each ⇒ Object
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 |