german_numbers 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.overcommit.yml +33 -0
- data/.rspec +1 -0
- data/.rubocop.yml +67 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +43 -0
- data/README.md +35 -0
- data/Rakefile +4 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/data/de.yml +33 -0
- data/german_numbers.gemspec +30 -0
- data/lib/german_numbers.rb +14 -0
- data/lib/german_numbers/to_words.rb +63 -0
- data/lib/german_numbers/version.rb +5 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 92f164db2d96ce8b35a633516c6410e2fe115d86
|
4
|
+
data.tar.gz: e28f2f23636b84afc3788ff191375400952970a7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bc470cd757b52a2c27283c23a1c07fe854642e9b630aadbbc9c137cd199f46d91e96546c71dc05fc26b6232a7a2e964486addc158742552595edfec4623e848a
|
7
|
+
data.tar.gz: 84697dc0c43365af6a0ef8021a98db50b537fc643c6cb57a5412dbe1208611d6987bfa72bb2463d86f290e6f508d7a20dfef101c4311436b389ff57d5533c9d8
|
data/.gitignore
ADDED
data/.overcommit.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Use this file to configure the Overcommit hooks you wish to use. This will
|
2
|
+
# extend the default configuration defined in:
|
3
|
+
# https://github.com/brigade/overcommit/blob/master/config/default.yml
|
4
|
+
#
|
5
|
+
# At the topmost level of this YAML file is a key representing type of hook
|
6
|
+
# being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
|
7
|
+
# customize each hook, such as whether to only run it on certain files (via
|
8
|
+
# `include`), whether to only display output if it fails (via `quiet`), etc.
|
9
|
+
#
|
10
|
+
# For a complete list of hooks, see:
|
11
|
+
# https://github.com/brigade/overcommit/tree/master/lib/overcommit/hook
|
12
|
+
#
|
13
|
+
# For a complete list of options that you can use to customize hooks, see:
|
14
|
+
# https://github.com/brigade/overcommit#configuration
|
15
|
+
#
|
16
|
+
# Uncomment the following lines to make the configuration take effect.
|
17
|
+
|
18
|
+
PreCommit:
|
19
|
+
RuboCop:
|
20
|
+
enabled: true
|
21
|
+
on_warn: fail # Treat all warnings as failures
|
22
|
+
#
|
23
|
+
# TrailingWhitespace:
|
24
|
+
# enabled: true
|
25
|
+
# exclude:
|
26
|
+
# - '**/db/structure.sql' # Ignore trailing whitespace in generated files
|
27
|
+
#
|
28
|
+
#PostCheckout:
|
29
|
+
# ALL: # Special hook name that customizes all hooks of this type
|
30
|
+
# quiet: true # Change all post-checkout hooks to only display output on failure
|
31
|
+
#
|
32
|
+
# IndexTags:
|
33
|
+
# enabled: true # Generate a tags file with `ctags` each time HEAD changes
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper --color --order rand
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.4.2
|
3
|
+
|
4
|
+
Exclude:
|
5
|
+
- ./**/schema.rb
|
6
|
+
- Gemfile
|
7
|
+
- bin/*
|
8
|
+
- bundle/**/*
|
9
|
+
- vendor/**/*
|
10
|
+
|
11
|
+
DisplayCopNames: true
|
12
|
+
|
13
|
+
Metrics/LineLength:
|
14
|
+
Max: 120
|
15
|
+
Exclude:
|
16
|
+
- spec/**/*.rb
|
17
|
+
|
18
|
+
Metrics/BlockLength:
|
19
|
+
Exclude:
|
20
|
+
- spec/**/*.rb
|
21
|
+
|
22
|
+
Style/BlockDelimiters:
|
23
|
+
Exclude:
|
24
|
+
- spec/**/*.rb
|
25
|
+
|
26
|
+
Style/SignalException:
|
27
|
+
Exclude:
|
28
|
+
- app/services/**/*.rb
|
29
|
+
|
30
|
+
Metrics/AbcSize:
|
31
|
+
Max: 30
|
32
|
+
|
33
|
+
Metrics/CyclomaticComplexity:
|
34
|
+
Max: 7
|
35
|
+
|
36
|
+
Metrics/ParameterLists:
|
37
|
+
Max: 10
|
38
|
+
|
39
|
+
Metrics/MethodLength:
|
40
|
+
Max: 15
|
41
|
+
|
42
|
+
Style/PercentLiteralDelimiters:
|
43
|
+
PreferredDelimiters:
|
44
|
+
default: ()
|
45
|
+
'%i': '[]'
|
46
|
+
'%I': '[]'
|
47
|
+
'%r': '{}'
|
48
|
+
'%w': '()'
|
49
|
+
'%W': '()'
|
50
|
+
|
51
|
+
Style/RegexpLiteral:
|
52
|
+
Enabled: false
|
53
|
+
|
54
|
+
Lint/AmbiguousBlockAssociation:
|
55
|
+
Enabled: false
|
56
|
+
|
57
|
+
Bundler/OrderedGems:
|
58
|
+
Enabled: false
|
59
|
+
|
60
|
+
Metrics/ClassLength:
|
61
|
+
Max: 200
|
62
|
+
|
63
|
+
Style/ClassAndModuleChildren:
|
64
|
+
Enabled: false
|
65
|
+
|
66
|
+
Documentation:
|
67
|
+
Enabled: false
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
german_numbers
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.2
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
german_numbers (0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
docile (1.1.5)
|
11
|
+
json (2.1.0)
|
12
|
+
rake (10.5.0)
|
13
|
+
rspec (3.7.0)
|
14
|
+
rspec-core (~> 3.7.0)
|
15
|
+
rspec-expectations (~> 3.7.0)
|
16
|
+
rspec-mocks (~> 3.7.0)
|
17
|
+
rspec-core (3.7.1)
|
18
|
+
rspec-support (~> 3.7.0)
|
19
|
+
rspec-expectations (3.7.0)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.7.0)
|
22
|
+
rspec-mocks (3.7.0)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.7.0)
|
25
|
+
rspec-support (3.7.0)
|
26
|
+
simplecov (0.15.1)
|
27
|
+
docile (~> 1.1.0)
|
28
|
+
json (>= 1.8, < 3)
|
29
|
+
simplecov-html (~> 0.10.0)
|
30
|
+
simplecov-html (0.10.2)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
bundler (~> 1.16)
|
37
|
+
german_numbers!
|
38
|
+
rake (~> 10.0)
|
39
|
+
rspec (~> 3.7)
|
40
|
+
simplecov (~> 0.15)
|
41
|
+
|
42
|
+
BUNDLED WITH
|
43
|
+
1.16.1
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# GermanNumbers
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/german_numbers`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'german_numbers'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install german_numbers
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` 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/[USERNAME]/german_numbers.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'german_numbers'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/data/de.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
de:
|
2
|
+
0: 'null'
|
3
|
+
1: 'ein'
|
4
|
+
2: 'zwei'
|
5
|
+
3: 'drei'
|
6
|
+
4: 'vier'
|
7
|
+
5: 'fünf'
|
8
|
+
6: 'sechs'
|
9
|
+
7: 'sieben'
|
10
|
+
8: 'acht'
|
11
|
+
9: 'neun'
|
12
|
+
10: 'zehn'
|
13
|
+
11: 'elf'
|
14
|
+
12: 'zwölf'
|
15
|
+
13: 'dreizehn'
|
16
|
+
14: 'vierzehn'
|
17
|
+
15: 'fünfzehn'
|
18
|
+
16: 'sechzehn'
|
19
|
+
17: 'siebzehn'
|
20
|
+
18: 'achtzehn'
|
21
|
+
19: 'neunzehn'
|
22
|
+
20: 'zwanzig'
|
23
|
+
30: 'dreißig'
|
24
|
+
40: 'vierzig'
|
25
|
+
50: 'fünfzig'
|
26
|
+
60: 'sechzig'
|
27
|
+
70: 'siebzig'
|
28
|
+
80: 'achtzig'
|
29
|
+
90: 'neunzig'
|
30
|
+
100: 'hundert'
|
31
|
+
1000: 'tausend'
|
32
|
+
1_000_000: 'Million'
|
33
|
+
1_000_000_000: 'Milliarde'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
lib = File.expand_path('../lib', __FILE__)
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
require 'german_numbers'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'german_numbers'
|
10
|
+
spec.version = GermanNumbers::VERSION
|
11
|
+
spec.authors = ['Gleb Sinyavsky']
|
12
|
+
spec.email = ['zhulik.gleb@gmail.com']
|
13
|
+
|
14
|
+
spec.summary = 'Gem for converting numbers to german words and vise-versa.'
|
15
|
+
spec.description = 'Gem for converting numbers to german words and vise-versa.'
|
16
|
+
spec.homepage = 'https://github.com/zhulik/german_words'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
22
|
+
spec.bindir = 'exe'
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.7'
|
29
|
+
spec.add_development_dependency 'simplecov', '~> 0.15'
|
30
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'german_numbers/version'
|
4
|
+
require 'german_numbers/to_words'
|
5
|
+
|
6
|
+
module GermanNumbers
|
7
|
+
DIGITS = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'data', 'de.yml'))['de']
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def words(ws)
|
11
|
+
ToWords.new.words(ws)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module GermanNumbers
|
6
|
+
class ToWords
|
7
|
+
def words(number)
|
8
|
+
raise ArgumentError if number > 999_999_999_999 || number.negative?
|
9
|
+
return postprocess(DIGITS[number]) unless DIGITS[number].nil?
|
10
|
+
|
11
|
+
number = number.to_s.rjust(12, '0')
|
12
|
+
|
13
|
+
billions, millions, thousands, number = number.to_s.reverse.scan(/.{1,3}/).map do |part|
|
14
|
+
part.reverse.to_i
|
15
|
+
end.reverse
|
16
|
+
|
17
|
+
postprocess(process(billions, millions, thousands, number))
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def process(billions, millions, thousands, number)
|
23
|
+
result = under_thousand(number)
|
24
|
+
result = "#{under_thousand(thousands)}#{DIGITS[1000]}#{result}" unless thousands.zero?
|
25
|
+
unless millions.zero?
|
26
|
+
n = under_thousand(millions)
|
27
|
+
result = "#{n == 'ein' ? 'eine' : n} #{decline(millions, DIGITS[1_000_000])} #{result}"
|
28
|
+
end
|
29
|
+
unless billions.zero?
|
30
|
+
n = under_thousand(billions)
|
31
|
+
result = "#{n == 'ein' ? 'eine' : n} #{decline(billions, DIGITS[1_000_000_000])} #{result}"
|
32
|
+
end
|
33
|
+
result
|
34
|
+
end
|
35
|
+
|
36
|
+
def postprocess(result)
|
37
|
+
result += 's' if result.end_with?('ein')
|
38
|
+
result = 'ein' + result if %w(hundert tausend).include?(result)
|
39
|
+
result = 'eine ' + result if %w(Million Milliarde).include?(result)
|
40
|
+
result.strip
|
41
|
+
end
|
42
|
+
|
43
|
+
def under_thousand(number)
|
44
|
+
digits = number.to_s.split('').reverse.map(&:to_i)
|
45
|
+
result = under_hundred(digits.first(2))
|
46
|
+
result = DIGITS[digits.last] + DIGITS[100] + result if digits.count > 2
|
47
|
+
result
|
48
|
+
end
|
49
|
+
|
50
|
+
def under_hundred(digits)
|
51
|
+
return '' if digits.all?(&:zero?)
|
52
|
+
n = DIGITS["#{digits[1]}#{digits[0]}".to_i]
|
53
|
+
return n unless n.nil?
|
54
|
+
DIGITS[digits[0]] + 'und' + DIGITS[(digits[1] * 10)]
|
55
|
+
end
|
56
|
+
|
57
|
+
def decline(count, number)
|
58
|
+
return number if count == 1
|
59
|
+
return number + 'n' if number.end_with?('e')
|
60
|
+
number + 'en'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: german_numbers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gleb Sinyavsky
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-05 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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.15'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.15'
|
69
|
+
description: Gem for converting numbers to german words and vise-versa.
|
70
|
+
email:
|
71
|
+
- zhulik.gleb@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".overcommit.yml"
|
78
|
+
- ".rspec"
|
79
|
+
- ".rubocop.yml"
|
80
|
+
- ".ruby-gemset"
|
81
|
+
- ".ruby-version"
|
82
|
+
- Gemfile
|
83
|
+
- Gemfile.lock
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- bin/console
|
87
|
+
- bin/setup
|
88
|
+
- data/de.yml
|
89
|
+
- german_numbers.gemspec
|
90
|
+
- lib/german_numbers.rb
|
91
|
+
- lib/german_numbers/to_words.rb
|
92
|
+
- lib/german_numbers/version.rb
|
93
|
+
homepage: https://github.com/zhulik/german_words
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.6.14
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: Gem for converting numbers to german words and vise-versa.
|
117
|
+
test_files: []
|