Class: DataCatalog::Cursor

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Cursor

Returns a new instance of Cursor.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/cursor.rb', line 11

def initialize(options)
  @klass      = options[:klass]
  @query_hash = options[:query_hash]
  @response   = options[:response]
  @uri        = options[:uri]

  @page_size      = @response['page_size']
  @document_count = @response['document_count']
  @members        = members(@response)
  @page_count     = @response['page_count']
end

Instance Attribute Details

#document_countObject (readonly)

Returns the value of attribute document_count.



5
6
7
# File 'lib/cursor.rb', line 5

def document_count
  @document_count
end

#page_countObject (readonly)

Returns the value of attribute page_count.



6
7
8
# File 'lib/cursor.rb', line 6

def page_count
  @page_count
end

#page_sizeObject (readonly)

Returns the value of attribute page_size.



7
8
9
# File 'lib/cursor.rb', line 7

def page_size
  @page_size
end

Instance Method Details

#[](i) ⇒ Object



23
24
25
# File 'lib/cursor.rb', line 23

def [](i)
  member_at(i)
end

#eachObject



27
28
29
# File 'lib/cursor.rb', line 27

def each
  @document_count.times { |i| yield member_at(i) }
end

#empty?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/cursor.rb', line 31

def empty?
  @document_count == 0
end

#firstObject



35
36
37
# File 'lib/cursor.rb', line 35

def first
  member_at(0)
end

#lastObject



39
40
41
# File 'lib/cursor.rb', line 39

def last
  member_at(@document_count - 1)
end

#lengthObject



43
44
45
# File 'lib/cursor.rb', line 43

def length
  @document_count
end

#page(page_number) ⇒ Object



47
48
49
# File 'lib/cursor.rb', line 47

def page(page_number)
  page_indices(page_number).map { |i| member_at(i) }
end

#sizeObject



51
52
53
# File 'lib/cursor.rb', line 51

def size
  @members.size
end