Class: Aerospike::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/aerospike/query/filter.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.Equal(bin_name, value) ⇒ Object



21
22
23
# File 'lib/aerospike/query/filter.rb', line 21

def self.Equal(bin_name, value)
  Filter.new(bin_name, value, value)
end

.geoContainsGeoJSONPoint(bin_name, point) ⇒ Object



39
40
41
42
# File 'lib/aerospike/query/filter.rb', line 39

def self.geoContainsGeoJSONPoint(bin_name, point)
  point = point.to_json
  Filter.new(bin_name, point, point, ParticleType::GEOJSON)
end

.geoContainsPoint(bin_name, lon, lat) ⇒ Object



44
45
46
47
# File 'lib/aerospike/query/filter.rb', line 44

def self.geoContainsPoint(bin_name, lon, lat)
  point = GeoJSON.new({type: "Point", coordinates: [lon, lat]})
  geoContainsGeoJSONPoint(bin_name, point)
end

.geoWithinGeoJSONRegion(bin_name, region) ⇒ Object



29
30
31
32
# File 'lib/aerospike/query/filter.rb', line 29

def self.geoWithinGeoJSONRegion(bin_name, region)
  region = region.to_json
  Filter.new(bin_name, region, region, ParticleType::GEOJSON)
end

.geoWithinRadius(bin_name, lon, lat, radius_meter) ⇒ Object



34
35
36
37
# File 'lib/aerospike/query/filter.rb', line 34

def self.geoWithinRadius(bin_name, lon, lat, radius_meter)
  region = GeoJSON.new({type: "AeroCircle", coordinates: [[lon, lat], radius_meter]})
  geoWithinGeoJSONRegion(bin_name, region)
end

.Range(bin_name, from, to) ⇒ Object



25
26
27
# File 'lib/aerospike/query/filter.rb', line 25

def self.Range(bin_name, from, to)
  Filter.new(bin_name, from, to)
end

Instance Method Details

#estimate_sizeObject



49
50
51
# File 'lib/aerospike/query/filter.rb', line 49

def estimate_size
  return @name.bytesize + @begin.estimate_size + @end.estimate_size + 10
end

#to_sObject

Show the filter as String. This is util to show filters in logs.



79
80
81
82
# File 'lib/aerospike/query/filter.rb', line 79

def to_s
  return "#{@name} = #{@begin}" if @begin == @end
  "#{@name} = #{@begin} - #{@end}"
end

#write(buf, offset) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/aerospike/query/filter.rb', line 53

def write(buf, offset)
  # Write name.
  len = buf.write_binary(@name, offset+1)
  buf.write_byte(len, offset)
  offset += len + 1

  # Write particle type.
  buf.write_byte(@val_type, offset)
  offset+=1

  # Write filter begin.
  len = @begin.write(buf, offset+4)
  buf.write_int32(len, offset)
  offset += len + 4

  # Write filter end.
  len = @end.write(buf, offset+4)
  buf.write_int32(len, offset)
  offset += len + 4

  offset
end