Class: RankmiLocalization::Location

Inherits:
ApplicationRecord show all
Defined in:
app/models/rankmi_localization/location.rb

Constant Summary collapse

DIVISIONS =

Constants

{
  ar: { pais: 0, provincia: 1, departamento: 2 },
  cl: { pais: 0, region: 1, provincia: 2, comuna: 3 },
  pe: { pais: 0, departamento: 1, provincia: 2, distrito: 3 },
  mx: { pais: 0, estado: 1, municipio: 2, ciudad: 3, colonia: 4 }
}.freeze
COUNTRIES =
{
  ar: 'Argentina',
  cl: 'Chile',
  pe: 'Perú',
  mx: 'México'
}.freeze

Class Method Summary collapse

Methods inherited from ApplicationRecord

table_name

Class Method Details

.country(country) ⇒ Object

Class methods



83
84
85
86
87
88
89
# File 'app/models/rankmi_localization/location.rb', line 83

def self.country(country)
  Rails.cache.fetch("Location::Country::#{country.upcase}") do
    find_by(name: COUNTRIES[country.downcase.to_sym],
            deep_level: deep_level_by_country(country, :pais),
            parent_id: nil)
  end
end

.deep_level_by_country(country, division) ⇒ Object



91
92
93
# File 'app/models/rankmi_localization/location.rb', line 91

def self.deep_level_by_country(country, division)
  DIVISIONS.dig(country.downcase.to_sym, division.downcase.to_sym)
end