to_chitanda 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +9 -0
- data/lib/to_chitanda.rb +9 -0
- data/lib/to_chitanda/chitanda.rb +16 -0
- data/lib/to_chitanda/kansuuji.rb +51 -0
- data/lib/to_chitanda/version.rb +3 -0
- data/spec/to_chitanda/chitanda_spec.rb +29 -0
- data/spec/to_chitanda/kansuuji_spec.rb +52 -0
- data/spec/to_chitanda_spec.rb +15 -0
- data/to_chitanda.gemspec +21 -0
- metadata +83 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 HORII Keima
|
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,31 @@
|
|
1
|
+
# ToChitanda
|
2
|
+
|
3
|
+
Integer#to_chitanda
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'to_chitanda'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install to_chitanda
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
1000.to_chitanda #=> "千反田える"
|
23
|
+
```
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/to_chitanda.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'to_chitanda/kansuuji'
|
3
|
+
|
4
|
+
module ToChitanda
|
5
|
+
module Chitanda
|
6
|
+
def chitanda(number)
|
7
|
+
"#{Kansuuji.kansuuji(number)}反田#{alpha_kana(number)}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def alpha_kana(number)
|
11
|
+
%w(えー びー しー でー いー えふ じー えいち あい じぇー けー える えむ えぬ おー ぴー きゅー あーる えす てー ゆー ぶい だぶりゅー えっくす わい ぜっと)[(number-1) % 26]
|
12
|
+
end
|
13
|
+
|
14
|
+
extend self
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
module ToChitanda
|
5
|
+
module Kansuuji
|
6
|
+
|
7
|
+
KANJI_NUMBERS = %w(〇 一 二 三 四 五 六 七 八 九)
|
8
|
+
LOWER_RANKS = [nil] + %w(十 百 千)
|
9
|
+
UPPER_RANKS = [nil] + %w(万 億 兆)
|
10
|
+
MAX_NUMBER = 1_0000_0000_0000_0000
|
11
|
+
|
12
|
+
def kansuuji(number)
|
13
|
+
raise ArgumentError, "can't calculate negative number" if number < 0
|
14
|
+
raise ArgumentError, "can't calculate gte #{MAX_NUMBER}" if number >= MAX_NUMBER
|
15
|
+
return KANJI_NUMBERS[0] if number == 0
|
16
|
+
|
17
|
+
ranks = UPPER_RANKS.dup
|
18
|
+
results = []
|
19
|
+
|
20
|
+
while number > 0
|
21
|
+
number, lower = number.divmod(10000)
|
22
|
+
results << "#{kansuuji_lower(lower, ranks.shift)}"
|
23
|
+
end
|
24
|
+
|
25
|
+
results.reverse.join
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def kansuuji_lower(number, suffix = nil)
|
30
|
+
return '' if number == 0
|
31
|
+
return "#{KANJI_NUMBERS[number]}#{suffix}" if number <= 9
|
32
|
+
ranks = LOWER_RANKS.dup
|
33
|
+
kanjis = []
|
34
|
+
|
35
|
+
while number > 0
|
36
|
+
number, mod = number.divmod(10)
|
37
|
+
rank = ranks.shift
|
38
|
+
kanji = case mod
|
39
|
+
when 0; ''
|
40
|
+
when 1; rank || KANJI_NUMBERS[1]
|
41
|
+
else ; "#{KANJI_NUMBERS[mod]}#{rank}"
|
42
|
+
end
|
43
|
+
kanjis << kanji
|
44
|
+
end
|
45
|
+
|
46
|
+
"#{kanjis.reverse.join}#{suffix}"
|
47
|
+
end
|
48
|
+
|
49
|
+
extend self
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'minitest/spec'
|
3
|
+
require 'to_chitanda/chitanda'
|
4
|
+
|
5
|
+
describe ToChitanda::Chitanda do
|
6
|
+
describe "chitanda" do
|
7
|
+
it "chitanda(1000) -> 千反田える" do
|
8
|
+
ToChitanda::Chitanda.chitanda( 1).must_be :==, "一反田えー"
|
9
|
+
ToChitanda::Chitanda.chitanda(1000).must_be :==, "千反田える"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "alpha_kana" do
|
14
|
+
[
|
15
|
+
# argument, result
|
16
|
+
[ 1, "えー"],
|
17
|
+
[ 2, "びー"],
|
18
|
+
[ 27, "えー"],
|
19
|
+
[ 1000, "える"],
|
20
|
+
|
21
|
+
].each do |arg, expect|
|
22
|
+
|
23
|
+
it "give #{arg} returns #{expect}" do
|
24
|
+
ToChitanda::Chitanda.alpha_kana(arg).must_be :==, expect
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'minitest/spec'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'to_chitanda/kansuuji'
|
5
|
+
|
6
|
+
describe ToChitanda::Kansuuji do
|
7
|
+
describe "kansuuji(number)" do
|
8
|
+
include ToChitanda::Kansuuji
|
9
|
+
|
10
|
+
[
|
11
|
+
# argument, result
|
12
|
+
[ 0, "〇"],
|
13
|
+
[ 1, "一"],
|
14
|
+
[ 2, "二"],
|
15
|
+
|
16
|
+
[ 10, "十"],
|
17
|
+
[ 11, "十一"],
|
18
|
+
[ 12, "十二"],
|
19
|
+
[ 20, "二十"],
|
20
|
+
[ 21, "二十一"],
|
21
|
+
[ 100, "百"],
|
22
|
+
[ 321, "三百二十一"],
|
23
|
+
[ 1000, "千"],
|
24
|
+
[ 1321, "千三百二十一"],
|
25
|
+
|
26
|
+
[ 10000, "一万"],
|
27
|
+
[ 100000, "十万"],
|
28
|
+
[ 10001, "一万一"],
|
29
|
+
[1_0000_0000, "一億"],
|
30
|
+
|
31
|
+
[12_3456_7890_1234, "十二兆三千四百五十六億七千八百九十万千二百三十四"],
|
32
|
+
|
33
|
+
].each do |arg, result|
|
34
|
+
|
35
|
+
it "#{arg} -> #{result}" do
|
36
|
+
kansuuji(arg).must_be :==, result
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
it "lt 0 raises ArgumentError" do
|
42
|
+
lambda{ kansuuji(-1) }.must_raise ArgumentError
|
43
|
+
end
|
44
|
+
|
45
|
+
it "gte 1_0000_0000_0000_0000 raises ArgumentError" do
|
46
|
+
lambda{ kansuuji(1_0000_0000_0000_0000) }.must_raise ArgumentError
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'minitest/spec'
|
3
|
+
require 'to_chitanda'
|
4
|
+
|
5
|
+
describe Integer do
|
6
|
+
describe "#to_chitanda" do
|
7
|
+
it "chitanda(1000) -> 千反田える" do
|
8
|
+
1.to_chitanda.must_be :==, "一反田えー"
|
9
|
+
1000.to_chitanda.must_be :==, "千反田える"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
|
data/to_chitanda.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'to_chitanda/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "to_chitanda"
|
8
|
+
gem.version = ToChitanda::VERSION
|
9
|
+
gem.authors = ["HORII Keima"]
|
10
|
+
gem.email = ["holysugar@gmail.com"]
|
11
|
+
gem.description = %q{Integer#to_chitanda}
|
12
|
+
gem.summary = %q{Integer#to_chitanda, from "Kotenbu" series}
|
13
|
+
gem.homepage = "https://github.com/holysugar/to_chitanda"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rake'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: to_chitanda
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- HORII Keima
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Integer#to_chitanda
|
31
|
+
email:
|
32
|
+
- holysugar@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- lib/to_chitanda.rb
|
43
|
+
- lib/to_chitanda/chitanda.rb
|
44
|
+
- lib/to_chitanda/kansuuji.rb
|
45
|
+
- lib/to_chitanda/version.rb
|
46
|
+
- spec/to_chitanda/chitanda_spec.rb
|
47
|
+
- spec/to_chitanda/kansuuji_spec.rb
|
48
|
+
- spec/to_chitanda_spec.rb
|
49
|
+
- to_chitanda.gemspec
|
50
|
+
homepage: https://github.com/holysugar/to_chitanda
|
51
|
+
licenses: []
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
hash: -4440802922852199557
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
hash: -4440802922852199557
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 1.8.24
|
77
|
+
signing_key:
|
78
|
+
specification_version: 3
|
79
|
+
summary: Integer#to_chitanda, from "Kotenbu" series
|
80
|
+
test_files:
|
81
|
+
- spec/to_chitanda/chitanda_spec.rb
|
82
|
+
- spec/to_chitanda/kansuuji_spec.rb
|
83
|
+
- spec/to_chitanda_spec.rb
|