Class: GeoCodeCuracao

Inherits:
Object
  • Object
show all
Defined in:
lib/app/models/geo_code_curacao.rb

Defined Under Namespace

Classes: Neighbourhood, Street, Zone

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(geo_code_curacao) ⇒ GeoCodeCuracao

Returns a new instance of GeoCodeCuracao.



20
21
22
23
24
25
26
27
28
29
# File 'lib/app/models/geo_code_curacao.rb', line 20

def initialize(geo_code_curacao)
  return nil if geo_code_curacao.nil?
  decoded = geo_code_curacao.to_s.scan(/\d\d/)
  zone_code = decoded[0]
  neighbourhood_code = decoded[1]
  street_code = decoded[2]
  self.street = Street.find_by_ZONECODE_and_NBRHCODE_and_STREETCODE(zone_code,neighbourhood_code,street_code)
  self.neighbourhood = Neighbourhood.find_by_ZONECODE_and_NBRHCODE(zone_code,neighbourhood_code) if self.street
  self.zone = Zone.find_by_ZONECODE(zone_code) if self.street
end

Instance Attribute Details

#neighbourhoodObject

Returns the value of attribute neighbourhood.



3
4
5
# File 'lib/app/models/geo_code_curacao.rb', line 3

def neighbourhood
  @neighbourhood
end

#streetObject

Returns the value of attribute street.



3
4
5
# File 'lib/app/models/geo_code_curacao.rb', line 3

def street
  @street
end

#zoneObject

Returns the value of attribute zone.



3
4
5
# File 'lib/app/models/geo_code_curacao.rb', line 3

def zone
  @zone
end

Class Method Details

.lookup(term) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/app/models/geo_code_curacao.rb', line 39

def self.lookup(term)
  street = term.gsub(/\\/, '\&\&').gsub(/'/, "''")
  sql = "select CONCAT( CONCAT_WS( ', ', S.NAME, B.NAME, Z.NAME), ' (', LPAD( S.ZONECODE, 2, '0' ), LPAD( S.NBRHCODE, 2, '0' ), LPAD( S.STREETCODE, 2, '0' ), ')' ) 
            FROM Straatcode S,  Buurten B, Zones Z
            WHERE 
                B.RECORDTYPE='NBRHOOD'
            AND S.ZONECODE=Z.ZONECODE
            AND B.ZONECODE=Z.ZONECODE
            AND S.ZONECODE=B.ZONECODE
            AND S.NBRHCODE = B.NBRHCODE
            AND S.NAME LIKE '#{street}'
            ORDER BY S.NAME"
  q = []
  ActiveRecord::Base.connection.execute(sql).to_a.each do |r|
    q << { :label => r[0] }
  end
  q.to_json.html_safe
end

Instance Method Details

#presentationObject



35
36
37
# File 'lib/app/models/geo_code_curacao.rb', line 35

def presentation
  "#{street.name}, #{zone.name}"
end

#valid?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/app/models/geo_code_curacao.rb', line 31

def valid?
  not self.street.nil?
end