Class: Yerba::QueryResult

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

Instance Method Summary collapse

Constructor Details

#initialize(sequence, indices) ⇒ QueryResult

Returns a new instance of QueryResult.



7
8
9
10
# File 'lib/yerba/query_result.rb', line 7

def initialize(sequence, indices)
  @sequence = sequence
  @indices = indices
end

Instance Method Details

#[](position) ⇒ Object



18
19
20
21
22
# File 'lib/yerba/query_result.rb', line 18

def [](position)
  index = @indices[position]

  @sequence[index] if index
end

#eachObject



12
13
14
15
16
# File 'lib/yerba/query_result.rb', line 12

def each
  return enum_for(:each) unless block_given?

  @indices.each { |index| yield @sequence[index] }
end

#empty?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/yerba/query_result.rb', line 38

def empty?
  @indices.empty?
end

#firstObject



24
25
26
# File 'lib/yerba/query_result.rb', line 24

def first
  self[0]
end

#indicesObject



42
43
44
# File 'lib/yerba/query_result.rb', line 42

def indices
  @indices.dup
end

#inspectObject



46
47
48
# File 'lib/yerba/query_result.rb', line 46

def inspect
  "#<Yerba::QueryResult length=#{length}>"
end

#lastObject



28
29
30
# File 'lib/yerba/query_result.rb', line 28

def last
  self[-1]
end

#lengthObject Also known as: size, count



32
33
34
# File 'lib/yerba/query_result.rb', line 32

def length
  @indices.length
end