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.



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

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]
  #Hash[*['zone','neighbourhood','street'].zip(gecode.to_s.scan(/\d\d/).map(&:to_i)).flatten]
  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.



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

def neighbourhood
  @neighbourhood
end

#streetObject

Returns the value of attribute street.



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

def street
  @street
end

#zoneObject

Returns the value of attribute zone.



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

def zone
  @zone
end

Class Method Details

.find(*args) ⇒ Object



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

def self.find(*args)
  find_options = args.extract_options!
  if args.first.to_s == "all"
    # ActiveRecord::Base.sanitize_sql_for_conditions can not be called from here. Why?
    # http://www.ruby-forum.com/topic/80357, active_record/connection_adapter/Quoting.rb
    street = find_options[:conditions][1].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' ), ')' ) AS street
            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"
    ids = ActiveRecord::Base.connection.execute(sql)
  end
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