Class: EnrichmentDb::Geo::Region
- Inherits:
-
DatumModel
- Object
- DatumModel
- EnrichmentDb::Geo::Region
- Defined in:
- lib/enrichment_db/geo/region.rb
Constant Summary collapse
- DATABASE_NAME =
'geo'
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from DatumModel
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data) ⇒ Region
constructor
A new instance of Region.
Methods inherited from DatumModel
all, by_lambda, format_result, lazy_attr_reader
Constructor Details
#initialize(data) ⇒ Region
Returns a new instance of Region.
7 8 9 10 |
# File 'lib/enrichment_db/geo/region.rb', line 7 def initialize(data) @id = data['id'] @name = data['name'] end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
2 3 4 |
# File 'lib/enrichment_db/geo/region.rb', line 2 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/enrichment_db/geo/region.rb', line 3 def name @name end |
Class Method Details
.by_boundary(values) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/enrichment_db/geo/region.rb', line 29 def self.by_boundary(values) puts "Finding #{object_type} intersecting with some geohash" field_names = fields table = make_table_name query = "SELECT #{field_names} FROM #{DATABASE_NAME}.#{table} where ST_Within(ST_SetSRID(ST_GeomFromGeoHash($1), 4283), boundary)" begin result = EnrichmentDb.request(DATABASE_NAME, query, values) if result.ntuples == 1 puts "Found #{object_type}" result[0] else puts "Nothing found" nil end rescue PG::InternalError => e # This usually is GEOSContains: TopologyException: side location conflict at #{lat} #{long} LexerAPI.error e.class LexerAPI.error e. return nil end end |
.by_id(id) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/enrichment_db/geo/region.rb', line 12 def self.by_id(id) puts "Finding #{object_type} with id = '#{id}'." field_names = fields table = make_table_name query = "SELECT #{field_names} FROM #{DATABASE_NAME}.#{table} where id = $1" values = [id] result = EnrichmentDb.request(DATABASE_NAME, query, values) if result.ntuples == 1 puts "Found #{object_type}" result[0] else puts "Nothing found" nil end end |