Sha256: fa8cc566ae1723e9bc8dedc0f6daa4077e103426ae877e9d2bbb9f664205c9a8

Contents?: true

Size: 1.74 KB

Versions: 208

Compression:

Stored size: 1.74 KB

Contents

# -*- encoding : utf-8 -*-
class GeoCodeCuracao
  attr_accessor :street, :neighbourhood, :zone
  
  class Zone < ActiveRecord::Base
    set_table_name "Zones"
    alias_attribute :name, :NAME
  end

  class Neighbourhood < ActiveRecord::Base
    set_table_name "Buurten"
    alias_attribute :name, :NAME
  end

  class Street < ActiveRecord::Base
    set_table_name "Straatcode"
    alias_attribute :name, :NAME
  end

  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

  def valid?
    not self.street.nil?
  end

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

  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
end

Version data entries

208 entries across 208 versions & 1 rubygems

Version Path
inline_forms-1.5.1 lib/app/models/geo_code_curacao.rb
inline_forms-1.5.0 lib/app/models/geo_code_curacao.rb
inline_forms-1.4.9 lib/app/models/geo_code_curacao.rb
inline_forms-1.4.8 lib/app/models/geo_code_curacao.rb
inline_forms-1.4.7 lib/app/models/geo_code_curacao.rb
inline_forms-1.4.6 lib/app/models/geo_code_curacao.rb
inline_forms-1.4.5 lib/app/models/geo_code_curacao.rb
inline_forms-1.4.4 lib/app/models/geo_code_curacao.rb
inline_forms-1.4.3 lib/app/models/geo_code_curacao.rb
inline_forms-1.4.2 lib/app/models/geo_code_curacao.rb
inline_forms-1.4.1 lib/app/models/geo_code_curacao.rb
inline_forms-1.4.0 lib/app/models/geo_code_curacao.rb
inline_forms-1.3.49 lib/app/models/geo_code_curacao.rb
inline_forms-1.3.48 lib/app/models/geo_code_curacao.rb
inline_forms-1.3.47 lib/app/models/geo_code_curacao.rb
inline_forms-1.3.45 lib/app/models/geo_code_curacao.rb
inline_forms-1.3.44 lib/app/models/geo_code_curacao.rb
inline_forms-1.3.43 lib/app/models/geo_code_curacao.rb
inline_forms-1.3.42 lib/app/models/geo_code_curacao.rb
inline_forms-1.3.41 lib/app/models/geo_code_curacao.rb