Class: City
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- City
- Defined in:
- app/models/city.rb
Instance Method Summary collapse
-
#containers ⇒ Object
Returns an array with all the parents of this city.
Instance Method Details
#containers ⇒ Object
Returns an array with all the parents of this city
The first position in the array is the country and up to 4 more positions can contain the ADM1, ADM2, ADM3 and ADM4 divisions containing the city
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/models/city.rb', line 9 def containers return @containers unless @containers.nil? container_codes = [] codes = code.split('|') container_codes << (codes = codes[0..-2]).join('|') while codes.size > 1 # first is country code @containers = [country] # second, third can be parent administrative division if not nil # NOTE container codes is like: ["ES|58|PO", "ES|58", "ES"] (country is last) @containers += Division.find_all_by_code container_codes[0..-2], :order => :level if container_codes.size > 1 return @containers end |