Class: Basho::DB::City

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/basho/db/city.rb

Overview

市区町村のActiveRecordモデル(+basho_cities+ テーブル)。 メモリ版 City と同じAPI(+full_name+, +capital?+)を提供する。

Instance Method Summary collapse

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


26
# File 'lib/basho/db/city.rb', line 26

def active? = deprecated_at.nil?

#currentBasho::DB::City

合併チェーンをたどって現行の自治体を返す(ループ検出・深度制限付き)。

Returns:



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/basho/db/city.rb', line 31

def current
  city = self
  seen = Set.new
  while city.successor_code.present? && seen.add?(city.successor_code)
    break if seen.size > MAX_SUCCESSOR_DEPTH

    next_city = city.successor
    break unless next_city

    city = next_city
  end
  city
end

#deprecated?Boolean

Returns:

  • (Boolean)


25
# File 'lib/basho/db/city.rb', line 25

def deprecated? = deprecated_at.present?

#full_nameString

郡名付きの正式名を返す。

Returns:

  • (String)


48
49
50
# File 'lib/basho/db/city.rb', line 48

def full_name
  district ? "#{district}#{name}" : name
end