chocoby / jp_prefecture Goto Github PK
View Code? Open in Web Editor NEWConvert japan prefecture code (JIS X 0402 based) into prefecture name.
Home Page: https://rubygems.org/gems/jp_prefecture
License: MIT License
Convert japan prefecture code (JIS X 0402 based) into prefecture name.
Home Page: https://rubygems.org/gems/jp_prefecture
License: MIT License
メンテナンスが終了している Ruby/Rails をサポート外にする。
サポート対象のバージョンはそれぞれ以下のページに公開されている。
便利なGemを作成いただきありがとうございます! 🎉
JpPrefecture::Prefecture.find(name: 'hoge') は name / name_e / name_h / name_k
を前方一致で検索するという仕様のため、以下のようケースで意図しないレコードが取得されてしまいます。
jp_prefecture/lib/jp_prefecture/prefecture.rb
Line 129 in f2a5a35
# 例:レコードが取得できないことを期待しているが、青森のレコードが取得される
JpPrefecture::Prefecture.find(name: '東')
=> #<JpPrefecture::Prefecture:0x00007fc550158890 @area="東北", @code=2, @name="青森県", @name_e="Aomori", @name_h="あおもりけん", @name_k="アオモリケン", @type="県", @zips=[185501..185501, 300111..395346]>
JpPrefecture::Prefecture.find
の引数が name
の場合は、 name
のみを検索対象とするJpPrefecture::Prefecture.find
の引数に name_e / name_h / name_k
をうけれるようにするとすれば解決しそうですが、前方一致だと同じような問題が起きる可能性があります。
とりいそぎのレポートです。
JpPrefecture::Prefecture.find(name: '東京都')
NoMethodError: undefined method `start_with?' for 1:Integer
from /bundle/gems/jp_prefecture-0.9.0/lib/jp_prefecture/prefecture.rb:131:in `block (2 levels) in find_code_by_name'
コードとラベルが相互に変換出来るようになると良い
find
メソッドと同居:
find(13)
find(name: "東京都")
find(name_e: "Tokyo")
Prefecture
クラスのインスタンスを返す
Rails 3/4 系の最新版でテストを行うようにする
デフォルトでは全て小文字で格納しておいて、name_e
を生成する時に capitalize
するようにした方が、検索処理などのバランスが良さそう。
検索系のメソッドがごちゃごちゃしているので整理したい
https://www.rubydoc.info/github/chocoby/jp_prefecture/master/JpPrefecture%2FPrefecture.find
海外の開発者が日本でサービスを立ち上げるときにも気軽に使えるようにしたい
JpPrefecture::Prefecture.find(name: xxx)
に対して、引数に空の文字列、nilが与えられた場合の挙動がおかしいように思います。
JpPrefecture::Prefecture.find(name: '') # => <JpPrefecture::Prefecture:0x007fdd21b17938 @code=1, @name="北海道", @name_e="Hokkaido", @name_h="ほっかいどう", @name_k="ホッカイドウ", @zips=[10000..70895, 400000..996509], @area="北海道">
JpPrefecture::Prefecture.find(name: nil) # => NoMethodError: undefined method `downcase' for nil:NilClass
これらの挙動については、nilを返すか、例外を投げるかしたほうが良いように思います。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.