zen_to_i 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 20ae563c900afbfa6fc761963d4681d2c2587c94
4
+ data.tar.gz: c16c6dc6b45e3bc814520098d41e38fcfaf4503c
5
+ SHA512:
6
+ metadata.gz: 31d7381ead1a505723e0792543553485cc7bd11ebbcd28a2bd9dce7be03234df59bbe4e8bc9fe5c705bb46144c11562af17f28ab6f165c97a1bbf1d936396654
7
+ data.tar.gz: 5bf98e31bb851c4552a084c96c4b5911c39a0a2ab4f57441d47646dcbc56f80cc252409550b82204050683bfae7549ba27e9828e5428398b030da70d0f1607aa
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in zen_to_i.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 yoshitsugu
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # ZenToI
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ gem 'zen_to_i'
8
+
9
+ And then execute:
10
+
11
+ $ bundle
12
+
13
+ Or install it yourself as:
14
+
15
+ $ gem install zen_to_i
16
+
17
+ ## Usage
18
+ 兆までの漢数字を半角数字に変換します。
19
+ 漢数字が続いていたらそれぞれ変換します。
20
+
21
+ ```ruby
22
+ "hoge".zen_to_i
23
+ #=> "hoge"
24
+
25
+ "一二三".zen_to_i
26
+ #=> "123"
27
+
28
+ "百三".zen_to_i
29
+ #=> "103"
30
+ "三兆五十二万四十八".zen_to_i
31
+ #=> "3000000520048"
32
+ ```
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,10 @@
1
+ class String
2
+ module Zen2Num
3
+ KANNUM = { '〇' => 0, '' => 1,'一' => 1, '二' => 2,'三' => 3, '四' => 4,
4
+ '五' => 5, '六' => 6, '七' => 7, '八' => 8, '九' => 9 }
5
+ KANORDER = {'十' => 10,'百' => 100, '千' => 1000 , '' => 1}
6
+ KANORDER_F = { '万' => 10**4 , '億' => 10**8, '兆' => 10**12 , ''=> 1}
7
+ ALL_KANSUUJI = KANNUM.keys + KANORDER.keys + KANORDER_F.keys
8
+ MAX_LOOP = 100
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module ZenToI
2
+ VERSION = "0.0.1"
3
+ end
data/lib/zen_to_i.rb ADDED
@@ -0,0 +1,87 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'zen_to_i/version'
5
+ require 'zen_to_i/constant'
6
+
7
+ class String
8
+ module Zen2Num
9
+ def zen_to_i
10
+ result = kanji2num(self)
11
+ zen2han(result)
12
+ end
13
+
14
+ def kanji2num(string)
15
+ array = split_kansuuji(string)
16
+ array = split_kansuuji_detail(array)
17
+ result = convert_kansuuji(array)
18
+ result.join('')
19
+ end
20
+
21
+ def zen2han str
22
+ str.tr("0-9","0-9")
23
+ end
24
+
25
+ private
26
+
27
+ #漢数字のところだけ切り出す
28
+ def split_kansuuji(string)
29
+ string.split(/([#{ALL_KANSUUJI.join('')}]+)/)
30
+ end
31
+
32
+ #位を表す数ではない普通の漢数字が続いていたらわける
33
+ def split_kansuuji_detail(array)
34
+ array_tmp = array.clone
35
+ array_result = array.clone
36
+ (1..MAX_LOOP).each{|i|
37
+ array_result = split_kansuuji_detail_inner(array_result)
38
+ if array_result == array_tmp
39
+ return array_result
40
+ else
41
+ array_tmp = array_result.clone
42
+ end
43
+ }
44
+ array_result
45
+ end
46
+
47
+ def split_kansuuji_detail_inner(array)
48
+ array.map{|a|
49
+ if( a =~ /([#{ALL_KANSUUJI.join('')}]+)/)
50
+ kannum = KANNUM.keys.join('')
51
+ a.gsub(/([#{kannum}])([#{kannum}])/,'\1,\2').split(",")
52
+ else
53
+ a
54
+ end
55
+ }.flatten
56
+ end
57
+
58
+ # 4桁ごとの単位(万、億、兆など)でまずわけ、
59
+ # それぞれに対して漢数字→数字を実行している。
60
+ def convert_kansuuji(array)
61
+ array.map{|a|
62
+ if( a =~ /([#{ALL_KANSUUJI.join('')}]+)/)
63
+ reg_order_f = /([^#{KANORDER_F.keys.join('')}]*)([#{KANORDER_F.keys.join('')}]?)/
64
+ a.scan( reg_order_f ).inject(0) do |ret, (lt_1000, order_f)|
65
+ reg_order = /([^#{KANORDER.keys.join('')}]*)([#{KANORDER.keys.join('')}]?)/
66
+ lt_1000_i = lt_1000.scan( reg_order ).inject(-1) do |tmp, (_1_9, order)|
67
+ tmp + KANNUM[_1_9].to_i * KANORDER[order].to_i
68
+ end
69
+ ret + lt_1000_i * KANORDER_F[order_f].to_i
70
+ end
71
+ else
72
+ a
73
+ end
74
+ }
75
+ end
76
+
77
+
78
+ def format_location string
79
+ location_map.each{|key,value|
80
+ string.gsub!(/#{key}/,value)
81
+ }
82
+ string
83
+ end
84
+
85
+ end
86
+ include Zen2Num
87
+ end
data/zen_to_i.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'zen_to_i/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "zen_to_i"
8
+ spec.version = ZenToI::VERSION
9
+ spec.authors = ["yoshitsugu"]
10
+ spec.email = ["zeroinon1206bass@gmail.com"]
11
+ spec.description = %q{全角文字に含まれる数字を半角の数値に変換。兆まで対応}
12
+ spec.summary = %q{Japanese zenkaku to number}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zen_to_i
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - yoshitsugu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: 全角文字に含まれる数字を半角の数値に変換。兆まで対応
42
+ email:
43
+ - zeroinon1206bass@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/zen_to_i.rb
54
+ - lib/zen_to_i/constant.rb
55
+ - lib/zen_to_i/version.rb
56
+ - zen_to_i.gemspec
57
+ homepage: ''
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.0.3
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Japanese zenkaku to number
81
+ test_files: []