Class: LocalGovCode
- Inherits:
-
Object
- Object
- LocalGovCode
- Includes:
- Singleton
- Defined in:
- lib/local_gov_code.rb,
lib/local_gov_code/version.rb,
lib/local_gov_code/local_gov_data.rb
Defined Under Namespace
Classes: LocalGov
Constant Summary collapse
- VERSION =
"1.0.0"
Instance Method Summary collapse
-
#all ⇒ Object
すべてのLocalGovの配列を返す。順番は地方自治体コード順。.
-
#find(code) ⇒ Object
5桁の地方公共団体コードに該当するLocalGovオブジェクトを返す コードは文字列でも整数でも可。 例)北海道 ‘01000’ or 1000.
-
#find_by_fullname(fullname) ⇒ Object
都道府県+市区町村名で検索.
-
#find_by_name(name) ⇒ Object
市区町村名で検索.
-
#initialize ⇒ LocalGovCode
constructor
A new instance of LocalGovCode.
Constructor Details
#initialize ⇒ LocalGovCode
Returns a new instance of LocalGovCode.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/local_gov_code.rb', line 10 def initialize @code_hash = {} @fullname_hash = {} @name_hash = {} data.each do |lg| local_gov = LocalGov.new(*lg) @code_hash[local_gov.code.to_i] = local_gov @fullname_hash[local_gov.name] = [] if @fullname_hash[local_gov.name].nil? @fullname_hash[local_gov.name] << local_gov @name_hash[local_gov.name] = [] if @name_hash[local_gov.name].nil? @name_hash[local_gov.name] << local_gov end @code_hash.freeze @fullname_hash.freeze @name_hash.freeze end |
Instance Method Details
#all ⇒ Object
すべてのLocalGovの配列を返す。順番は地方自治体コード順。
49 50 51 |
# File 'lib/local_gov_code.rb', line 49 def all @code_hash.sort.collect { |lg| lg.last } end |
#find(code) ⇒ Object
5桁の地方公共団体コードに該当するLocalGovオブジェクトを返す コードは文字列でも整数でも可。 例)北海道 ‘01000’ or 1000
34 35 36 |
# File 'lib/local_gov_code.rb', line 34 def find(code) @code_hash[code.to_i] end |
#find_by_fullname(fullname) ⇒ Object
都道府県+市区町村名で検索
39 40 41 |
# File 'lib/local_gov_code.rb', line 39 def find_by_fullname(fullname) @fullname_hash[fullname] end |
#find_by_name(name) ⇒ Object
市区町村名で検索
44 45 46 |
# File 'lib/local_gov_code.rb', line 44 def find_by_name(name) @name_hash[name] end |