兆までの漢数字を半角数字に変換します。 漢数字が続いていたらそれぞれ変換します。
install via rubygems
$ gem install zen_to_i
Or, you can use bundler. Please add this line to your application's Gemfile:
gem 'zen_to_i'
And then execute:
$ bundle
$ zen_to_i "一二三"
123
# or you can use with pipe
$ echo "一二三" | zen_to_i
123
Please call bundle exec zen_to_i
if you install this gem via bundler.
require 'zen_to_i'
"hoge".zen_to_i
#=> "hoge"
"一二三".zen_to_i
#=> "123"
"百三".zen_to_i
#=> "103"
"三兆五十二万四十八".zen_to_i
#=> "3000000520048"
Note that zen_to_i
returns String, not Integer.
Or you can overwrite to_i
method with Refinements.
This returns Integer same as default to_i
method.
require "zen_to_i/refine"
using ZenToI::Refine
"一二三".zen_to_i
#=> "123"
"一二三".to_i
#=> 123
Also, you can implicitly overwrite to_i
method by require "zen_to_i/string_ext"
.
Of course it is very dangerous. Please be careful to use it.
require "zen_to_i/string_ext"
"一二三".zen_to_i
#=> "123"
"一二三".to_i
#=> 123
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request