Class: Yerba::QueryResult
- Inherits:
-
Object
- Object
- Yerba::QueryResult
- Includes:
- Enumerable
- Defined in:
- lib/yerba/query_result.rb
Instance Method Summary collapse
- #[](position) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #first ⇒ Object
- #indices ⇒ Object
-
#initialize(sequence, indices) ⇒ QueryResult
constructor
A new instance of QueryResult.
- #inspect ⇒ Object
- #last ⇒ Object
- #length ⇒ Object (also: #size, #count)
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 |
#each ⇒ Object
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
38 39 40 |
# File 'lib/yerba/query_result.rb', line 38 def empty? @indices.empty? end |
#first ⇒ Object
24 25 26 |
# File 'lib/yerba/query_result.rb', line 24 def first self[0] end |
#indices ⇒ Object
42 43 44 |
# File 'lib/yerba/query_result.rb', line 42 def indices @indices.dup end |
#inspect ⇒ Object
46 47 48 |
# File 'lib/yerba/query_result.rb', line 46 def inspect "#<Yerba::QueryResult length=#{length}>" end |
#last ⇒ Object
28 29 30 |
# File 'lib/yerba/query_result.rb', line 28 def last self[-1] end |
#length ⇒ Object Also known as: size, count
32 33 34 |
# File 'lib/yerba/query_result.rb', line 32 def length @indices.length end |