Class: Basho::Data::Loader Private
- Inherits:
-
Object
- Object
- Basho::Data::Loader
- 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.("../../../data", __dir__)
Class Method Summary collapse
-
.cities(prefecture_code) ⇒ Array<Hash>
private
指定した都道府県の市区町村データを返す。.
-
.deprecated_cities ⇒ Array<Hash>
private
廃止された市区町村データを返す。.
-
.deprecated_city(code) ⇒ Hash?
private
廃止コードで1件検索する(ハッシュインデックスによる O(1) ルックアップ)。.
-
.postal_codes(prefix) ⇒ Array<Hash>
private
指定したプレフィックスの郵便番号データを返す。.
-
.prefectures ⇒ Array<Hash>
private
全47都道府県データを返す。.
-
.reset! ⇒ void
private
全キャッシュをクリアする。.
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.
指定した都道府県の市区町村データを返す。
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_cities ⇒ 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.
廃止された市区町村データを返す。
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) ルックアップ)。
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.
指定したプレフィックスの郵便番号データを返す。
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 |
.prefectures ⇒ 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.
全47都道府県データを返す。
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 |