Class: UbigeoRails::Ubigeo

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/ubigeo_rails/ubigeo.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.children_of(*departments) ⇒ Object



49
50
51
# File 'app/models/ubigeo_rails/ubigeo.rb', line 49

def self.children_of(*departments)
  where(parent_id: departments)
end

.departmentsObject



45
46
47
# File 'app/models/ubigeo_rails/ubigeo.rb', line 45

def self.departments
  with_parent nil
end

.with_parent(parent_id) ⇒ Object



41
42
43
# File 'app/models/ubigeo_rails/ubigeo.rb', line 41

def self.with_parent(parent_id)
  where parent_id: parent_id
end

Instance Method Details

#department_partObject



29
30
31
# File 'app/models/ubigeo_rails/ubigeo.rb', line 29

def department_part
  id.to_s[0..1]
end

#district_partObject



37
38
39
# File 'app/models/ubigeo_rails/ubigeo.rb', line 37

def district_part
  id.to_s[4..5]
end

#has_department?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'app/models/ubigeo_rails/ubigeo.rb', line 17

def has_department?
  digits >= 1 && digits <= 6
end

#has_district?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'app/models/ubigeo_rails/ubigeo.rb', line 25

def has_district?
  digits >= 5 && digits <= 6
end

#has_province?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'app/models/ubigeo_rails/ubigeo.rb', line 21

def has_province?
  digits >= 3 && digits <= 6
end

#province_partObject



33
34
35
# File 'app/models/ubigeo_rails/ubigeo.rb', line 33

def province_part
  id.to_s[2..3]
end