japanese_numbers 0.1.0

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
+ SHA256:
3
+ metadata.gz: 3652769e239cb438a8d1f2146009b9572f6c7af0f7681f68cb392d87d868fdd3
4
+ data.tar.gz: 15cae8bc7009583b8df00807d66fee860b556d90532d59104e0934869cb50144
5
+ SHA512:
6
+ metadata.gz: 7f44984e6729cfc1b1abbb4be1f3a88ea084bbd9966c46cf10624c6b3ffd80c7f5aa98e587a5a54466d381a5c9f8e4e7ba609e95656bac96c969837a93e9eb9d
7
+ data.tar.gz: 53af9f9d752d7d7a020b9655a5ab3b476e52882f1d2cf339c36df273edb1e2c6bfb61b7d23a10af5ff506f9de21b67b9914c47f623be372915f820891c0c707b
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in japanese_numbers.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 osyoyu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # JapaneseNumbers
2
+
3
+ Parser for Japanese numbers like "123万4567" or "5000兆円".
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'japanese_numbers'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install japanese_numbers
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ JapaneseNumbers::Parser.parse("5000兆円") #=> 5000000000000000
25
+ ```
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bundle install` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/osyoyu/japanese_numbers.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,22 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "japanese_numbers/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "japanese_numbers"
7
+ spec.version = JapaneseNumbers::VERSION
8
+ spec.authors = ["osyoyu"]
9
+ spec.email = ["osyoyu@osyoyu.com"]
10
+
11
+ spec.summary = %q{Parser for Japanese numbers like "123万4567" or "5000兆円".}
12
+ spec.homepage = "https://github.com/osyoyu/ruby-japanese_numbers"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.16"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ end
@@ -0,0 +1,2 @@
1
+ require "japanese_numbers/version"
2
+ require "japanese_numbers/parser"
@@ -0,0 +1,31 @@
1
+ class JapaneseNumbers::Parser
2
+ DELIMITERS = {
3
+ '万' => 10000,
4
+ '億' => 100000000,
5
+ '兆' => 1000000000000,
6
+ '京' => 10000000000000000,
7
+ }
8
+
9
+ def self.parse(str)
10
+ JIntParser.new.parse(str)
11
+ end
12
+
13
+ def parse(str)
14
+ parts = split_to_parts(str)
15
+ res = parts.inject(0) do |sum, part|
16
+ sum + part[0].to_i * (DELIMITERS[part[1]] || 1)
17
+ end
18
+ res
19
+ end
20
+
21
+ def split_to_parts(str)
22
+ parts = []
23
+ loop do
24
+ coefficient, unit, remains = str.partition(Regexp.union(DELIMITERS.keys))
25
+ parts.push([coefficient, unit])
26
+ str = remains
27
+ break if str == ""
28
+ end
29
+ parts
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module JapaneseNumbers
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: japanese_numbers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - osyoyu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-05-02 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description:
42
+ email:
43
+ - osyoyu@osyoyu.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - japanese_numbers.gemspec
54
+ - lib/japanese_numbers.rb
55
+ - lib/japanese_numbers/parser.rb
56
+ - lib/japanese_numbers/version.rb
57
+ homepage: https://github.com/osyoyu/ruby-japanese_numbers
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.7.3
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Parser for Japanese numbers like "123万4567" or "5000兆円".
81
+ test_files: []