Class: Unidom::Geo::China::Region

Inherits:
ApplicationRecord show all
Includes:
Common::Concerns::ModelExtension, Concerns::AsInferiorRegion, Concerns::AsSuperiorRegion, Unidom::Geo::Concerns::AsRegion
Defined in:
app/models/unidom/geo/china/region.rb

Overview

Region 是中国行政区划。《GB/T 2260-2007 中华人民共和国行政区划代码》数字码采用三层六位层次码结构,按层次分别表示我国各

字母代码的编制原则和结构

Constant Summary collapse

MDUCG_CODES =
[ '11', '12', '31', '50' ].freeze

Instance Method Summary collapse

Instance Method Details

#district?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'app/models/unidom/geo/china/region.rb', line 73

def district?
  numeric_code_suffix.to_i<20
end

#full_name(separator = ' ') ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
# File 'app/models/unidom/geo/china/region.rb', line 85

def full_name(separator = ' ')
  final_name     = self.name
  current_region = self
  count          = 0
  while current_region = current_region.super_regions.first
    count += 1
    final_name = "#{current_region.name}#{separator}#{final_name}" unless current_region.virtual?
    break if count>5
  end
  final_name
end

#mducg?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'app/models/unidom/geo/china/region.rb', line 81

def mducg?
  under_mducg? && numeric_code_middle_empty? && numeric_code_suffix_empty?
end

#numeric_code_middleObject



57
58
59
# File 'app/models/unidom/geo/china/region.rb', line 57

def numeric_code_middle
  numeric_code[2..3]
end

#numeric_code_middle_empty?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'app/models/unidom/geo/china/region.rb', line 65

def numeric_code_middle_empty?
  '00'==numeric_code_middle
end

#numeric_code_prefixObject



53
54
55
# File 'app/models/unidom/geo/china/region.rb', line 53

def numeric_code_prefix
  numeric_code[0..1]
end

#numeric_code_suffixObject



61
62
63
# File 'app/models/unidom/geo/china/region.rb', line 61

def numeric_code_suffix
  numeric_code[4..5]
end

#numeric_code_suffix_empty?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'app/models/unidom/geo/china/region.rb', line 69

def numeric_code_suffix_empty?
  '00'==numeric_code_suffix
end

#under?(region) ⇒ Boolean

Returns:

  • (Boolean)


97
98
99
100
101
102
# File 'app/models/unidom/geo/china/region.rb', line 97

def under?(region)
  return false unless region.numeric_code_prefix==numeric_code_prefix
  return false if     numeric_code_middle_empty?
  return true  if     region.numeric_code_middle_empty?
  numeric_code_suffix_empty? ? false : region.numeric_code_suffix_empty?
end

#under_mducg?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'app/models/unidom/geo/china/region.rb', line 77

def under_mducg?
  self.class::MDUCG_CODES.include? numeric_code_prefix
end