Class: NoBrainer::GeoResultSet
- Inherits:
-
Object
- Object
- NoBrainer::GeoResultSet
- Defined in:
- lib/nobrainer_geospatial.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#rql ⇒ Object
Returns the value of attribute rql.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #all ⇒ Object
- #count ⇒ Object
- #each(&block) ⇒ Object
- #first ⇒ Object
-
#initialize(klass, rql) ⇒ GeoResultSet
constructor
A new instance of GeoResultSet.
- #limit(n) ⇒ Object
- #order_by(args, order = :asc) ⇒ Object
- #skip(n) ⇒ Object
- #to_a ⇒ Object
- #to_rql ⇒ Object
- #where(args = nil, &block) ⇒ Object
Constructor Details
#initialize(klass, rql) ⇒ GeoResultSet
Returns a new instance of GeoResultSet.
9 10 11 12 |
# File 'lib/nobrainer_geospatial.rb', line 9 def initialize(klass, rql) self.rql = rql self.klass = klass end |
Instance Attribute Details
#klass ⇒ Object
Returns the value of attribute klass.
7 8 9 |
# File 'lib/nobrainer_geospatial.rb', line 7 def klass @klass end |
#rql ⇒ Object
Returns the value of attribute rql.
7 8 9 |
# File 'lib/nobrainer_geospatial.rb', line 7 def rql @rql end |
Instance Method Details
#[](index) ⇒ Object
77 78 79 |
# File 'lib/nobrainer_geospatial.rb', line 77 def [](index) to_a()[index] end |
#all ⇒ Object
18 19 20 |
# File 'lib/nobrainer_geospatial.rb', line 18 def all to_a end |
#count ⇒ Object
32 33 34 |
# File 'lib/nobrainer_geospatial.rb', line 32 def count NoBrainer.run { self.rql.count } end |
#each(&block) ⇒ Object
26 27 28 29 30 |
# File 'lib/nobrainer_geospatial.rb', line 26 def each(&block) NoBrainer.run { self.rql }.each do |result| block.call(new_from_db result) end end |
#first ⇒ Object
22 23 24 |
# File 'lib/nobrainer_geospatial.rb', line 22 def first new_from_db NoBrainer.run { self.rql }.first end |
#limit(n) ⇒ Object
44 45 46 |
# File 'lib/nobrainer_geospatial.rb', line 44 def limit(n) GeoResultSet.new(self.klass, self.rql.limit(n)) end |
#order_by(args, order = :asc) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/nobrainer_geospatial.rb', line 52 def order_by(args, order = :asc) conditions = [] raise "Invalid sort order: #{order}" unless order == :asc || order == :desc if args.class == Array conditions = args.map do |arg| if order == :asc RethinkDB::RQL.new.asc(arg) else RethinkDB::RQL.new.desc(arg) end end else if order == :asc conditions = RethinkDB::RQL.new.asc(args) else conditions = RethinkDB::RQL.new.desc(args) end end GeoResultSet.new(self.klass, self.rql.order_by(*conditions)) end |
#skip(n) ⇒ Object
48 49 50 |
# File 'lib/nobrainer_geospatial.rb', line 48 def skip(n) GeoResultSet.new(self.klass, self.rql.skip(n)) end |
#to_a ⇒ Object
14 15 16 |
# File 'lib/nobrainer_geospatial.rb', line 14 def to_a NoBrainer.run { self.rql }.to_a.map {|r| new_from_db(r) } end |
#to_rql ⇒ Object
81 82 83 |
# File 'lib/nobrainer_geospatial.rb', line 81 def to_rql self.rql end |
#where(args = nil, &block) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/nobrainer_geospatial.rb', line 36 def where(args = nil, &block) if block_given? GeoResultSet.new(self.klass, self.rql.filter(block)) else GeoResultSet.new(self.klass, self.rql.filter(args)) end end |