Class: JpPrefecture::Prefecture
- Inherits:
-
Object
- Object
- JpPrefecture::Prefecture
- Defined in:
- lib/jp_prefecture/prefecture.rb,
lib/jp_prefecture/prefecture/finder.rb
Overview
都道府県のコードと名前を扱うクラス
Defined Under Namespace
Classes: Finder
Instance Attribute Summary collapse
-
#area ⇒ Object
Returns the value of attribute area.
-
#code ⇒ Object
Returns the value of attribute code.
-
#name ⇒ Object
Returns the value of attribute name.
-
#name_e ⇒ Object
Returns the value of attribute name_e.
-
#name_h ⇒ Object
Returns the value of attribute name_h.
-
#name_k ⇒ Object
Returns the value of attribute name_k.
-
#name_r ⇒ Object
Returns the value of attribute name_r.
-
#type ⇒ Object
Returns the value of attribute type.
-
#zips ⇒ Object
Returns the value of attribute zips.
Class Method Summary collapse
-
.all ⇒ Array<JpPrefecture::Prefecture>
すべての都道府県を取得.
-
.build_by_code(code) ⇒ JpPrefecture::Prefecture?
都道府県コードから都道府県インスタンスを作成.
-
.find(args) ⇒ JpPrefecture::Prefecture?
都道府県を検索.
Instance Attribute Details
#area ⇒ Object
Returns the value of attribute area.
10 11 12 |
# File 'lib/jp_prefecture/prefecture.rb', line 10 def area @area end |
#code ⇒ Object
Returns the value of attribute code.
10 11 12 |
# File 'lib/jp_prefecture/prefecture.rb', line 10 def code @code end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/jp_prefecture/prefecture.rb', line 10 def name @name end |
#name_e ⇒ Object
Returns the value of attribute name_e.
10 11 12 |
# File 'lib/jp_prefecture/prefecture.rb', line 10 def name_e @name_e end |
#name_h ⇒ Object
Returns the value of attribute name_h.
10 11 12 |
# File 'lib/jp_prefecture/prefecture.rb', line 10 def name_h @name_h end |
#name_k ⇒ Object
Returns the value of attribute name_k.
10 11 12 |
# File 'lib/jp_prefecture/prefecture.rb', line 10 def name_k @name_k end |
#name_r ⇒ Object
Returns the value of attribute name_r.
10 11 12 |
# File 'lib/jp_prefecture/prefecture.rb', line 10 def name_r @name_r end |
#type ⇒ Object
Returns the value of attribute type.
10 11 12 |
# File 'lib/jp_prefecture/prefecture.rb', line 10 def type @type end |
#zips ⇒ Object
Returns the value of attribute zips.
10 11 12 |
# File 'lib/jp_prefecture/prefecture.rb', line 10 def zips @zips end |
Class Method Details
.all ⇒ Array<JpPrefecture::Prefecture>
すべての都道府県を取得
57 58 59 |
# File 'lib/jp_prefecture/prefecture.rb', line 57 def self.all Mapping.data.map { |code, _| build_by_code(code) } end |
.build_by_code(code) ⇒ JpPrefecture::Prefecture?
都道府県コードから都道府県インスタンスを作成
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/jp_prefecture/prefecture.rb', line 21 def self.build_by_code(code) # rubocop:disable Metrics/AbcSize result = Mapping.data[code] return unless result pref = new pref.code = code pref.name = result[:name] pref.name_e = result[:name_e].try(:capitalize) pref.name_r = result[:name_r].try(:capitalize) pref.name_h = result[:name_h] pref.name_k = result[:name_k] pref.zips = ZipMapping.data[code] pref.area = result[:area] pref.type = case pref.name.try(:slice, -1) when '都', '道', '府', '県' pref.name[-1] end pref end |
.find(args) ⇒ JpPrefecture::Prefecture?
都道府県を検索
文字列は前方一致で検索する
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/jp_prefecture/prefecture.rb', line 98 def self.find(args) return if args.nil? case args when Integer, String JpPrefecture::Prefecture::Finder.new.find(field: nil, value: args) when Hash search_field = args.keys.first search_value = args.values.first JpPrefecture::Prefecture::Finder.new.find(field: search_field, value: search_value) end end |