Class: Basho::Data::Loader Private

Inherits:
Object
  • Object
show all
Defined in:
lib/basho/data/loader.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

同梱JSONデータの遅延読み込みとキャッシュ。 各メソッドは初回呼び出し時にJSONファイルを読み込み、以降はキャッシュを返す。

Constant Summary collapse

DATA_DIR =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

同梱JSONデータのディレクトリパス

File.expand_path("../../../data", __dir__)

Class Method Summary collapse

Class Method Details

.cities(prefecture_code) ⇒ Array<Hash>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

指定した都道府県の市区町村データを返す。

Parameters:

  • prefecture_code (Integer)

    都道府県コード

Returns:

  • (Array<Hash>)


28
29
30
# File 'lib/basho/data/loader.rb', line 28

def cities(prefecture_code)
  cities_cache[prefecture_code] ||= load_json("cities/#{format("%02d", prefecture_code)}.json")
end

.deprecated_citiesArray<Hash>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

廃止された市区町村データを返す。

Returns:

  • (Array<Hash>)


35
36
37
# File 'lib/basho/data/loader.rb', line 35

def deprecated_cities
  @deprecated_cities ||= load_json("deprecated_cities.json")
end

.deprecated_city(code) ⇒ Hash?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

廃止コードで1件検索する(ハッシュインデックスによる O(1) ルックアップ)。

Parameters:

  • code (String)

    6桁自治体コード

Returns:

  • (Hash, nil)


43
44
45
# File 'lib/basho/data/loader.rb', line 43

def deprecated_city(code)
  deprecated_cities_by_code[code]
end

.postal_codes(prefix) ⇒ Array<Hash>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

指定したプレフィックスの郵便番号データを返す。

Parameters:

  • prefix (String)

    3桁プレフィックス(例: "154")

Returns:

  • (Array<Hash>)


51
52
53
# File 'lib/basho/data/loader.rb', line 51

def postal_codes(prefix)
  postal_cache[prefix] ||= load_json("postal_codes/#{prefix}.json")
end

.prefecturesArray<Hash>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

全47都道府県データを返す。

Returns:

  • (Array<Hash>)


20
21
22
# File 'lib/basho/data/loader.rb', line 20

def prefectures
  @prefectures ||= load_json("prefectures.json")
end

.reset!void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

全キャッシュをクリアする。



58
59
60
# File 'lib/basho/data/loader.rb', line 58

def reset!
  instance_variables.each { |var| remove_instance_variable(var) }
end