number_words 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 +18 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +65 -0
- data/Rakefile +1 -0
- data/lib/number_words.rb +22 -0
- data/lib/number_words/core_ext.rb +7 -0
- data/lib/number_words/version.rb +3 -0
- data/number_words.gemspec +28 -0
- data/spec/plugin_spec.rb +33 -0
- data/spec/spec_helper.rb +17 -0
- metadata +140 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 conanite
|
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,65 @@
|
|
1
|
+
# NumberWords
|
2
|
+
|
3
|
+
It is not realistic to expect a single maintainer to be sufficiently
|
4
|
+
polyglottous to be able to manage a system for writing numbers as words in a
|
5
|
+
variety of languages. Furthermore, the rules in various languages vary to such
|
6
|
+
an extent that there is little use in attempting to impose a single framework
|
7
|
+
(beyond a collection of utilities).
|
8
|
+
|
9
|
+
This gem provides a central point into which locale-specific number-to-word gems
|
10
|
+
can hook.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
The gems for the locales you support should depend on this gem, so under normal
|
15
|
+
circumstances once you've installed those, this is installed also. For example,
|
16
|
+
if you add
|
17
|
+
|
18
|
+
gem 'number_words_fr'
|
19
|
+
|
20
|
+
to your Gemfile, you'll have this gem too.
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
require 'number_words/core_ext'
|
25
|
+
|
26
|
+
I18n.locale = :fr
|
27
|
+
123.to_words # => "cent vingt-trois"
|
28
|
+
|
29
|
+
If you don't want to monkey-patch Integer, you can do this instead:
|
30
|
+
|
31
|
+
I18n.locale = :fr
|
32
|
+
NumberWords.int_to_words 123 # => "cent vingt-trois"
|
33
|
+
|
34
|
+
'number_words/core_ext' isn't "require"d by default
|
35
|
+
|
36
|
+
## available locales
|
37
|
+
|
38
|
+
gem 'number_words_fr' # French
|
39
|
+
gem 'number_words_en' # English (using short-scale billions)
|
40
|
+
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
### There are two ways to contribute - firstly the usual:
|
45
|
+
|
46
|
+
1. Fork it ( http://github.com/<my-github-username>/number_words/fork )
|
47
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
48
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
+
5. Create new Pull Request
|
51
|
+
|
52
|
+
### secondly
|
53
|
+
|
54
|
+
1. if you want to contribute a locale, make your own gem that plugs into this thus:
|
55
|
+
|
56
|
+
class RussianNumberWords
|
57
|
+
def int_to_words i, options={}
|
58
|
+
# ur code here
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
NumberWords.add_handler :ru, RussianNumberWords.new
|
63
|
+
|
64
|
+
2. publish the gem
|
65
|
+
3. let me know and I'll add a link here
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/number_words.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "number_words/version"
|
2
|
+
|
3
|
+
module NumberWords
|
4
|
+
@@handlers = { }
|
5
|
+
|
6
|
+
def self.int_to_words int, options={ }
|
7
|
+
@@handlers[I18n.locale.to_sym].int_to_words(int.to_i, options).strip
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.add_handler locale, handler
|
11
|
+
@@handlers[locale] = handler
|
12
|
+
end
|
13
|
+
|
14
|
+
class Base
|
15
|
+
def split_by_thousands n
|
16
|
+
sub = [n % 1000]
|
17
|
+
sup = n / 1000
|
18
|
+
sub + (sup > 0 ? split_by_thousands(sup) : [])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- coding: utf-8; mode: ruby -*-
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'number_words/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |gem|
|
9
|
+
gem.name = "number_words"
|
10
|
+
gem.version = NumberWords::VERSION
|
11
|
+
gem.authors = ["Conan Dalton"]
|
12
|
+
gem.license = 'MIT'
|
13
|
+
gem.email = ["conan@conandalton.net"]
|
14
|
+
gem.description = %q{entry point for federated number-to-words handling}
|
15
|
+
gem.summary = %q{entry point for federated number-to-words handling}
|
16
|
+
gem.homepage = "https://github.com/conanite/number_words"
|
17
|
+
|
18
|
+
gem.add_dependency 'i18n'
|
19
|
+
gem.add_development_dependency 'rspec', '~> 2.9'
|
20
|
+
gem.add_development_dependency 'rspec_numbering_formatter'
|
21
|
+
gem.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
gem.add_development_dependency "rake"
|
23
|
+
|
24
|
+
gem.files = `git ls-files`.split($/)
|
25
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
26
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
27
|
+
gem.require_paths = ["lib"]
|
28
|
+
end
|
data/spec/plugin_spec.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'i18n'
|
3
|
+
require 'number_words/core_ext'
|
4
|
+
|
5
|
+
describe "plugin system" do
|
6
|
+
|
7
|
+
class ElvishPlugin
|
8
|
+
def int_to_words i, options={ }
|
9
|
+
"#{i} in Elvish"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class KlingonPlugin
|
14
|
+
def int_to_words i, options={ }
|
15
|
+
"#{i} in Klingon"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
before {
|
20
|
+
NumberWords.add_handler :el, ElvishPlugin.new
|
21
|
+
NumberWords.add_handler :kl, KlingonPlugin.new
|
22
|
+
}
|
23
|
+
|
24
|
+
it "should delegate to the registered Klingon plugin" do
|
25
|
+
I18n.locale = :kl
|
26
|
+
expect(123.to_words).to eq "123 in Klingon"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should delegate to the registered Elvish plugin" do
|
30
|
+
I18n.locale = :el
|
31
|
+
expect(123.to_words).to eq "123 in Elvish"
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: number_words
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Conan Dalton
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-03-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: i18n
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
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
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.9'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.9'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec_numbering_formatter
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.5'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.5'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rake
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: entry point for federated number-to-words handling
|
95
|
+
email:
|
96
|
+
- conan@conandalton.net
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- .rspec
|
103
|
+
- Gemfile
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- lib/number_words.rb
|
108
|
+
- lib/number_words/core_ext.rb
|
109
|
+
- lib/number_words/version.rb
|
110
|
+
- number_words.gemspec
|
111
|
+
- spec/plugin_spec.rb
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
homepage: https://github.com/conanite/number_words
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 1.8.24
|
135
|
+
signing_key:
|
136
|
+
specification_version: 3
|
137
|
+
summary: entry point for federated number-to-words handling
|
138
|
+
test_files:
|
139
|
+
- spec/plugin_spec.rb
|
140
|
+
- spec/spec_helper.rb
|