figures 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +18 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +5 -0
- data/MIT-LICENSE.txt +20 -0
- data/README.md +24 -0
- data/Rakefile +30 -0
- data/figures.gemspec +21 -0
- data/lib/figures.rb +9 -0
- data/lib/figures/german.rb +89 -0
- data/lib/figures/version.rb +5 -0
- data/spec/figures_spec.rb +155 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: de702fb97a926179fce3f9980284d4b5bb08ac84
|
4
|
+
data.tar.gz: 01ce6d9a38a368679b3678670019fe44f24e9048
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 46e1fe163048f8b3d053217c3995fca5fd19f43fd6c3a9283b57078ea56e4e5cf733524b35c376ff790a396e6efee500102f305cfaa7971002129f6734cc0fa8
|
7
|
+
data.tar.gz: e536e4b30f22cae941cef4497949de67f85764f824e1ffcb04d915ec4a304d3cafd0d0adccd328b5f52a8f6f6ab93d31de4077984668146535c832619e1ff386
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Gemfile.lock
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2015 Paul Götze, paul.christoph.goetze@gmail.com
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# figures [![[version]](https://badge.fury.io/rb/figures.svg)](http://badge.fury.io/rb/figures) [![[travis]](https://travis-ci.org/paulgoetze/figures.png)](https://travis-ci.org/paulgoetze/figures)
|
2
|
+
|
3
|
+
German number words.
|
4
|
+
|
5
|
+
## Setup
|
6
|
+
|
7
|
+
Add to your `Gemfile`:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'figures'
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
require 'figures'
|
17
|
+
|
18
|
+
Figures.parse(1234, :de) # => 'eintausendzweihundertvierunddreißig'
|
19
|
+
```
|
20
|
+
|
21
|
+
|
22
|
+
## MIT License
|
23
|
+
|
24
|
+
Copyright (C) 2015 Paul Götze. Released under the MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# # #
|
2
|
+
# Get gemspec info
|
3
|
+
|
4
|
+
gemspec_file = Dir['*.gemspec'].first
|
5
|
+
gemspec = eval File.read(gemspec_file), binding, gemspec_file
|
6
|
+
info = "#{gemspec.name} | #{gemspec.version} | " \
|
7
|
+
"#{gemspec.runtime_dependencies.size} dependencies | " \
|
8
|
+
"#{gemspec.files.size} files"
|
9
|
+
|
10
|
+
|
11
|
+
# # #
|
12
|
+
# Gem build and install task
|
13
|
+
|
14
|
+
desc info
|
15
|
+
task :gem do
|
16
|
+
puts info + "\n\n"
|
17
|
+
print " "; sh "gem build #{gemspec_file}"
|
18
|
+
FileUtils.mkdir_p 'pkg'
|
19
|
+
FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
|
20
|
+
puts; sh %{gem install --no-document pkg/#{gemspec.name}-#{gemspec.version}.gem}
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
# # #
|
25
|
+
# Start an IRB session with the gem loaded
|
26
|
+
|
27
|
+
desc "#{gemspec.name} | IRB"
|
28
|
+
task :irb do
|
29
|
+
sh "irb -I ./lib -r #{gemspec.name.gsub '-','/'}"
|
30
|
+
end
|
data/figures.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + "/lib/figures/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "figures"
|
7
|
+
gem.version = Figures::VERSION
|
8
|
+
gem.summary = "German number words"
|
9
|
+
gem.description = "German number words."
|
10
|
+
gem.authors = ["Paul Götze", "Jan Lelis"]
|
11
|
+
gem.email = "paul.christoph.goetze@gmail.com"
|
12
|
+
gem.homepage = "https://github.com/paulgoetze/figures"
|
13
|
+
gem.license = "MIT"
|
14
|
+
|
15
|
+
gem.files = Dir['{**/}{.*,*}'].select{ |path| File.file?(path) && path !~ /^pkg/ }
|
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.required_ruby_version = '~> 2.0'
|
21
|
+
end
|
data/lib/figures.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
module Figures
|
2
|
+
class German
|
3
|
+
WORDS = {
|
4
|
+
copula: "und",
|
5
|
+
digits: %w[null ein zwei drei vier fünf sechs sieben acht neun],
|
6
|
+
tens: %w[eine zehn zwanzig dreißig vierzig fünfzig sechzig siebzig achzig neunzig],
|
7
|
+
exponents: %w[hundert tausend million milliarden billion billiarden trillion trilliarden quadrillionen quadrilliarden quintillion sextillion sextilliarden]
|
8
|
+
}.freeze
|
9
|
+
|
10
|
+
def initialize(number)
|
11
|
+
@number = number.to_i
|
12
|
+
end
|
13
|
+
|
14
|
+
def parse
|
15
|
+
return WORDS[:digits][@number] if @number < 10 && @number >= 0
|
16
|
+
|
17
|
+
number_string = @number.to_s.reverse.scan(/.{1,3}/).map.with_index{ |number_part, index|
|
18
|
+
parse_triple(number_part.reverse.to_i, index)
|
19
|
+
}.reverse.join
|
20
|
+
|
21
|
+
number_string.sub! /^und/, '' # TODO investigate
|
22
|
+
|
23
|
+
if @number < 0
|
24
|
+
"minus #{number_string}"
|
25
|
+
else
|
26
|
+
number_string
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def parse_triple(number, triple_index)
|
31
|
+
temp_number = number.abs
|
32
|
+
number_word = ""
|
33
|
+
temp_tens = ""
|
34
|
+
|
35
|
+
return 'eins' if temp_number == 1 && triple_index == 0 # FIXME
|
36
|
+
|
37
|
+
while temp_number > 0
|
38
|
+
decimal_power = Math.log10(temp_number).floor
|
39
|
+
number_base = 10 ** decimal_power
|
40
|
+
number_tail = temp_number - (temp_number % number_base)
|
41
|
+
digit = number_tail / number_base
|
42
|
+
|
43
|
+
copula = ((digit > 1) ? WORDS[:copula] : "")
|
44
|
+
leading_single = (triple_index >= 2 && digit == 1) ? WORDS[:tens][0].to_s : WORDS[:digits][digit].to_s
|
45
|
+
|
46
|
+
if decimal_power == 2
|
47
|
+
number_word << WORDS[:digits][digit].to_s << WORDS[:exponents][0].to_s
|
48
|
+
end
|
49
|
+
|
50
|
+
if decimal_power == 0 && !temp_tens.empty?
|
51
|
+
number_word << WORDS[:digits][digit].to_s
|
52
|
+
end
|
53
|
+
|
54
|
+
if decimal_power == 0 && temp_tens.empty?
|
55
|
+
number_word << copula << leading_single
|
56
|
+
end
|
57
|
+
|
58
|
+
if decimal_power == 1
|
59
|
+
temp_tens << copula << WORDS[:tens][digit].to_s
|
60
|
+
end
|
61
|
+
|
62
|
+
temp_number = temp_number - number_tail
|
63
|
+
end
|
64
|
+
|
65
|
+
number_word << temp_tens
|
66
|
+
|
67
|
+
if triple_index > 0
|
68
|
+
number_word << WORDS[:exponents][triple_index].to_s
|
69
|
+
end
|
70
|
+
|
71
|
+
number_word = handle_exceptions(number_word)
|
72
|
+
number_word = remove_wrong_leadings(number_word)
|
73
|
+
|
74
|
+
number_word
|
75
|
+
end
|
76
|
+
|
77
|
+
def handle_exceptions(word)
|
78
|
+
word = word.gsub('einzehn', 'elf')
|
79
|
+
word = word.gsub('zweizehn', 'zwölf')
|
80
|
+
word = word.gsub('sechszehn', 'sechzehn')
|
81
|
+
word = word.gsub('siebenzehn', 'siebzehn')
|
82
|
+
end
|
83
|
+
|
84
|
+
def remove_wrong_leadings(word)
|
85
|
+
word.gsub(/^(und|null)/, '')
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
require_relative "../lib/figures"
|
2
|
+
require "minitest/autorun"
|
3
|
+
|
4
|
+
describe Figures do
|
5
|
+
describe '.parse' do
|
6
|
+
describe '[german]' do
|
7
|
+
it 'parses -1' do
|
8
|
+
assert_equal 'minus eins', Figures.parse(-1, :de)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'parses 0' do
|
12
|
+
assert_equal 'null', Figures.parse(0, :de)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'parses 1' do
|
16
|
+
assert_equal 'eins', Figures.parse(1, :de)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'parses 2' do
|
20
|
+
assert_equal 'zwei', Figures.parse(2, :de)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'parses 3' do
|
24
|
+
assert_equal 'drei', Figures.parse(3, :de)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'parses 4' do
|
28
|
+
assert_equal 'vier', Figures.parse(4, :de)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'parses 5' do
|
32
|
+
assert_equal 'fünf', Figures.parse(5, :de)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'parses 6' do
|
36
|
+
assert_equal 'sechs', Figures.parse(6, :de)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'parses 7' do
|
40
|
+
assert_equal 'sieben', Figures.parse(7, :de)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'parses 8' do
|
44
|
+
assert_equal 'acht', Figures.parse(8, :de)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'parses 9' do
|
48
|
+
assert_equal 'neun', Figures.parse(9, :de)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'parses 10' do
|
52
|
+
assert_equal 'zehn', Figures.parse(10, :de)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'parses 11' do
|
56
|
+
assert_equal 'elf', Figures.parse(11, :de)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'parses 12' do
|
60
|
+
assert_equal 'zwölf', Figures.parse(12, :de)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'parses 13' do
|
64
|
+
assert_equal 'dreizehn', Figures.parse(13, :de)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'parses 14' do
|
68
|
+
assert_equal 'vierzehn', Figures.parse(14, :de)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'parses 15' do
|
72
|
+
assert_equal 'fünfzehn', Figures.parse(15, :de)
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'parses 16' do
|
76
|
+
assert_equal 'sechzehn', Figures.parse(16, :de)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'parses 17' do
|
80
|
+
assert_equal 'siebzehn', Figures.parse(17, :de)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'parses 18' do
|
84
|
+
assert_equal 'achtzehn', Figures.parse(18, :de)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'parses 19' do
|
88
|
+
assert_equal 'neunzehn', Figures.parse(19, :de)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'parses 20' do
|
92
|
+
assert_equal 'zwanzig', Figures.parse(20, :de)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'parses 21' do
|
96
|
+
assert_equal 'einundzwanzig', Figures.parse(21, :de)
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'parses 30' do
|
100
|
+
assert_equal 'dreißig', Figures.parse(30, :de)
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'parses 99' do
|
104
|
+
assert_equal 'neunundneunzig', Figures.parse(99, :de)
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'parses 100' do
|
108
|
+
assert_equal 'einhundert', Figures.parse(100, :de)
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'parses 101' do
|
112
|
+
assert_equal 'einhunderteins', Figures.parse(101, :de)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'parses 199' do
|
116
|
+
assert_equal 'einhundertneunundneunzig', Figures.parse(199, :de)
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'parses 200' do
|
120
|
+
assert_equal 'zweihundert', Figures.parse(200, :de)
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'parses 999' do
|
124
|
+
assert_equal 'neunhundertneunundneunzig', Figures.parse(999, :de)
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'parses 1_000' do
|
128
|
+
assert_equal 'eintausend', Figures.parse(1000, :de)
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'parses 1_234' do
|
132
|
+
assert_equal 'eintausendzweihundertvierunddreißig', Figures.parse(1_234, :de)
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'parses 10_000' do
|
136
|
+
assert_equal 'zehntausend', Figures.parse(10_000, :de)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'parses 100_000' do
|
140
|
+
assert_equal 'einhunderttausend', Figures.parse(100_000, :de)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'parses 1_000_000' do
|
144
|
+
fail 'figure out'
|
145
|
+
assert_equal 'million', Figures.parse(1_000_000, :de)
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'parses 2_000_000' do
|
149
|
+
fail 'figure out'
|
150
|
+
assert_equal 'zwei millionen', Figures.parse(1_000_000, :de)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: figures
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul Götze
|
8
|
+
- Jan Lelis
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-10-26 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: German number words.
|
15
|
+
email: paul.christoph.goetze@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".travis.yml"
|
22
|
+
- CHANGELOG.md
|
23
|
+
- Gemfile
|
24
|
+
- MIT-LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- figures.gemspec
|
28
|
+
- lib/figures.rb
|
29
|
+
- lib/figures/german.rb
|
30
|
+
- lib/figures/version.rb
|
31
|
+
- spec/figures_spec.rb
|
32
|
+
homepage: https://github.com/paulgoetze/figures
|
33
|
+
licenses:
|
34
|
+
- MIT
|
35
|
+
metadata: {}
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - "~>"
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '2.0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 2.4.5.1
|
53
|
+
signing_key:
|
54
|
+
specification_version: 4
|
55
|
+
summary: German number words
|
56
|
+
test_files:
|
57
|
+
- spec/figures_spec.rb
|
58
|
+
has_rdoc:
|