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.



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

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.



75
76
77
# File 'lib/finexclub/manager.rb', line 75

def core
  @core
end

#mongo_cursorObject

Returns the value of attribute mongo_cursor.



74
75
76
# File 'lib/finexclub/manager.rb', line 74

def mongo_cursor
  @mongo_cursor
end

Instance Method Details

#current_limitObject



110
111
112
# File 'lib/finexclub/manager.rb', line 110

def current_limit
  @mongo_cursor.limit
end

#current_skipObject



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

def current_skip
  @mongo_cursor.skip
end

#eachObject



102
103
104
105
106
107
108
# File 'lib/finexclub/manager.rb', line 102

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)


88
89
90
# File 'lib/finexclub/manager.rb', line 88

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

#limit(number_to_return) ⇒ Object



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

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

#next_documentObject Also known as: next



92
93
94
95
96
97
98
# File 'lib/finexclub/manager.rb', line 92

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



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

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

#sort(key_or_list, direction = nil) ⇒ Object



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

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