class Urbans::Province
Attributes
__id__[RW]
country_id[RW]
id[RW]
names[RW]
Public Class Methods
all!(_country_id, _locale=Urbans.locale)
click to toggle source
# File lib/urbans/foundations/province.rb, line 11 def self.all! _country_id, _locale=Urbans.locale provinces = [] country_id = _country_id.to_s.downcase.to_sym locale = _locale.to_s.downcase.to_sym from_file(country_id, locale).each do |_province_id, province_name| province_id = _province_id.to_s.downcase.to_sym Urbans::PROVINCES[country_id] ||= {} province = Urbans::PROVINCES[country_id][province_id] if province.nil? province = Urbans::Province.new province.__id__ = _province_id province.id = "#{country_id}.#{province_id}" province.names[locale] = province_name province.country_id = country_id Urbans::PROVINCES[country_id][province_id] = province end provinces << province end provinces end
from_file(_country_id, _locale)
click to toggle source
# File lib/urbans/foundations/province.rb, line 84 def self.from_file _country_id, _locale locale = _locale.to_s.downcase country_id = _country_id.to_s.downcase from_file = YAML.load_file(Urbans::URBAN_PATH + "urbans/data/#{locale}.#{country_id}.provinces.yml") from_file[locale]["provinces"][country_id] end
get(arg)
click to toggle source
get specific province
# File lib/urbans/foundations/province.rb, line 36 def self.get arg _country_id = _province_id = nil if arg.is_a?(Hash) _country_id, _province_id = arg.fetch(:country), arg[:province] elsif arg.is_a?(String) _arg = arg.split(".") _country_id, _province_id = _arg[0], _arg[1] end if _province_id.nil? return all! _country_id end country_id = _country_id.to_s.downcase.to_sym province_id = _province_id.to_s.downcase.to_sym if Urbans::PROVINCES[country_id].nil? || Urbans::PROVINCES[country_id][province_id].nil? all! country_id, Urbans.locale end province = Urbans::PROVINCES[country_id][province_id] province end
new()
click to toggle source
# File lib/urbans/foundations/province.rb, line 7 def initialize self.names = {} end
Public Instance Methods
<=>(another)
click to toggle source
for sorting
# File lib/urbans/foundations/province.rb, line 80 def <=> another self.name <=> another.name end
cities()
click to toggle source
# File lib/urbans/foundations/province.rb, line 75 def cities Urbans.city.get country: country_id, province: __id__ end
country()
click to toggle source
# File lib/urbans/foundations/province.rb, line 71 def country Urbans.country.get country_id end
name(_locale=Urbans.locale)
click to toggle source
# File lib/urbans/foundations/province.rb, line 60 def name _locale=Urbans.locale locale = _locale.to_s.downcase.to_sym if names[locale].nil? province_local_name = self.class.from_file(country_id, locale)[__id__] names[locale] = province_local_name end names[locale] end