Class: Finexclub::Manager::Cursor

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(core, obj_class, mongo_cursor) ⇒ Cursor

Returns a new instance of Cursor.



80
81
82
83
84
# File 'lib/finexclub/manager.rb', line 80

def initialize(core, obj_class, mongo_cursor)
  @core         = core
  @obj_class    = obj_class
  @mongo_cursor = mongo_cursor
end

Instance Attribute Details

#coreObject (readonly)

Returns the value of attribute core.



78
79
80
# File 'lib/finexclub/manager.rb', line 78

def core
  @core
end

#mongo_cursorObject

Returns the value of attribute mongo_cursor.



77
78
79
# File 'lib/finexclub/manager.rb', line 77

def mongo_cursor
  @mongo_cursor
end

Instance Method Details

#current_limitObject



113
114
115
# File 'lib/finexclub/manager.rb', line 113

def current_limit
  @mongo_cursor.limit
end

#current_skipObject



121
122
123
# File 'lib/finexclub/manager.rb', line 121

def current_skip
  @mongo_cursor.skip
end

#eachObject



105
106
107
108
109
110
111
# File 'lib/finexclub/manager.rb', line 105

def each
  @mongo_cursor.each do |doc|
    obj = @obj_class.new(core)
    obj.build(doc)
    yield(obj)
  end
end

#empty?Boolean

Is the cursor empty? This method is much more efficient than doing cursor.count == 0

Returns:

  • (Boolean)


91
92
93
# File 'lib/finexclub/manager.rb', line 91

def empty?
  @mongo_cursor.has_next? == false
end

#limit(number_to_return) ⇒ Object



117
118
119
# File 'lib/finexclub/manager.rb', line 117

def limit(number_to_return)
  @mongo_cursor.limit(number_to_return); self
end

#next_documentObject Also known as: next



95
96
97
98
99
100
101
# File 'lib/finexclub/manager.rb', line 95

def next_document
  if doc = @mongo_cursor.next_document
    obj = @obj_class.new(core)
    obj.build(doc)
    obj
  end
end

#skip(number_to_skip) ⇒ Object



125
126
127
# File 'lib/finexclub/manager.rb', line 125

def skip(number_to_skip)
  @mongo_cursor.skip(number_to_skip); self
end

#sort(key_or_list, direction = nil) ⇒ Object



129
130
131
# File 'lib/finexclub/manager.rb', line 129

def sort(key_or_list, direction = nil)
  @mongo_cursor.sort(key_or_list, direction); self
end