number_words_fr 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .#*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in number_words_fr.gemspec
4
+ gemspec
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,28 @@
1
+ # NumberWordsFr
2
+
3
+ Provides :fr locale for number_words gem
4
+
5
+ ## Installation
6
+
7
+ gem 'number_words_fr'
8
+ bundle
9
+
10
+ ## Usage
11
+
12
+ require 'number_words/core_ext'
13
+
14
+ I18n.locale = :fr
15
+ 123.to_words # => "cent vingt-trois"
16
+
17
+ If you don't want to monkey-patch Integer, you can do this instead:
18
+
19
+ I18n.locale = :fr
20
+ NumberWords.int_to_words 123 # => "cent vingt-trois"
21
+
22
+ ## Contributing
23
+
24
+ 1. Fork it ( http://github.com/<my-github-username>/number_words_fr/fork )
25
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
26
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
27
+ 4. Push to the branch (`git push origin my-new-feature`)
28
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,60 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require "number_words"
4
+ require "number_words_fr/version"
5
+ require "yaml"
6
+
7
+ module NumberWordsFr
8
+ WORDS = YAML::load File.read File.expand_path("../words.yml", __FILE__)
9
+
10
+ class Fr < NumberWords::Base
11
+ THOUSANDS = ["", "mille", "million", "milliard"]
12
+
13
+ def int_to_words int, options={}
14
+ case int
15
+ when 0; "zéro"
16
+ else
17
+ join_thousands THOUSANDS, split_by_thousands(int)
18
+ end
19
+ end
20
+
21
+ def hundreds_to_words int
22
+ h = int / 100
23
+ t = int % 100
24
+ if t == 0
25
+ case h;
26
+ when 0; "zéro";
27
+ when 1; "cent";
28
+ else "#{tens_to_words h} cents"
29
+ end
30
+ else
31
+ case h;
32
+ when 0; "#{tens_to_words t}";
33
+ when 1; "cent #{tens_to_words t}";
34
+ else "#{tens_to_words h} cent #{tens_to_words t}"
35
+ end
36
+ end
37
+ end
38
+
39
+ def tens_to_words i
40
+ WORDS["numbers"]["initial"][i]
41
+ end
42
+
43
+ def join_thousands names, amounts
44
+ working = amounts.zip(names)
45
+ working.delete_if { |amount, name| amount == 0 }
46
+ working = working.map { |amount, name|
47
+ if amount == 1 && name == 'mille'
48
+ [name]
49
+ elsif amount > 1 && name != 'mille' && name != ''
50
+ [hundreds_to_words(amount), "#{name}s"]
51
+ else
52
+ [hundreds_to_words(amount), name]
53
+ end
54
+ }
55
+ working.reverse.flatten.join(' ')
56
+ end
57
+ end
58
+
59
+ NumberWords.add_handler :fr, Fr.new
60
+ end
@@ -0,0 +1,3 @@
1
+ module NumberWordsFr
2
+ VERSION = "0.0.1"
3
+ end
data/lib/words.yml ADDED
@@ -0,0 +1,102 @@
1
+ numbers:
2
+ initial:
3
+ - zéro
4
+ - un
5
+ - deux
6
+ - trois
7
+ - quatre
8
+ - cinq
9
+ - six
10
+ - sept
11
+ - huit
12
+ - neuf
13
+ - dix
14
+ - onze
15
+ - douze
16
+ - treize
17
+ - quatorze
18
+ - quinze
19
+ - seize
20
+ - dix-sept
21
+ - dix-huit
22
+ - dix-neuf
23
+ - vingt
24
+ - vingt et un
25
+ - vingt-deux
26
+ - vingt-trois
27
+ - vingt-quatre
28
+ - vingt-cinq
29
+ - vingt-six
30
+ - vingt-sept
31
+ - vingt-huit
32
+ - vingt-neuf
33
+ - trente
34
+ - trente et un
35
+ - trente-deux
36
+ - trente-trois
37
+ - trente-quatre
38
+ - trente-cinq
39
+ - trente-six
40
+ - trente-sept
41
+ - trente-huit
42
+ - trente-neuf
43
+ - quarante
44
+ - quarante et un
45
+ - quarante-deux
46
+ - quarante-trois
47
+ - quarante-quatre
48
+ - quarante-cinq
49
+ - quarante-six
50
+ - quarante-sept
51
+ - quarante-huit
52
+ - quarante-neuf
53
+ - cinquante
54
+ - cinquante et un
55
+ - cinquante-deux
56
+ - cinquante-trois
57
+ - cinquante-quatre
58
+ - cinquante-cinq
59
+ - cinquante-six
60
+ - cinquante-sept
61
+ - cinquante-huit
62
+ - cinquante-neuf
63
+ - soixante
64
+ - soixante et un
65
+ - soixante-deux
66
+ - soixante-trois
67
+ - soixante-quatre
68
+ - soixante-cinq
69
+ - soixante-six
70
+ - soixante-sept
71
+ - soixante-huit
72
+ - soixante-neuf
73
+ - soixante-dix
74
+ - soixante et onze
75
+ - soixante-douze
76
+ - soixante-treize
77
+ - soixante-quatorze
78
+ - soixante-quinze
79
+ - soixante-seize
80
+ - soixante-dix-sept
81
+ - soixante-dix-huit
82
+ - soixante-dix-neuf
83
+ - quatre-vingts
84
+ - quatre-vingt-un
85
+ - quatre-vingt-deux
86
+ - quatre-vingt-trois
87
+ - quatre-vingt-quatre
88
+ - quatre-vingt-cinq
89
+ - quatre-vingt-six
90
+ - quatre-vingt-sept
91
+ - quatre-vingt-huit
92
+ - quatre-vingt-neuf
93
+ - quatre-vingt-dix
94
+ - quatre-vingt-onze
95
+ - quatre-vingt-douze
96
+ - quatre-vingt-treize
97
+ - quatre-vingt-quatorze
98
+ - quatre-vingt-quinze
99
+ - quatre-vingt-seize
100
+ - quatre-vingt-dix-sept
101
+ - quatre-vingt-dix-huit
102
+ - quatre-vingt-dix-neuf
@@ -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_fr/version'
7
+
8
+ Gem::Specification.new do |gem|
9
+ gem.name = "number_words_fr"
10
+ gem.version = NumberWordsFr::VERSION
11
+ gem.authors = ["Conan Dalton"]
12
+ gem.license = 'MIT'
13
+ gem.email = ["conan@conandalton.net"]
14
+ gem.description = %q{number_words handler for french}
15
+ gem.summary = %q{number_words handler for french}
16
+ gem.homepage = "https://github.com/conanite/number_words_fr"
17
+
18
+ gem.add_dependency 'number_words'
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
@@ -0,0 +1,73 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+ require 'i18n'
5
+ require 'number_words_fr'
6
+ require 'number_words/core_ext'
7
+
8
+
9
+ describe NumberWordsFr do
10
+ def expect_words n, txt
11
+ expect(n.to_words).to eq txt
12
+ end
13
+
14
+ before { I18n.locale = :fr }
15
+
16
+ it "should translate numbers into french" do
17
+ expect_words 0, "zéro"
18
+ expect_words 1, "un"
19
+ expect_words 2, "deux"
20
+ expect_words 10, "dix"
21
+ expect_words 12, "douze"
22
+ expect_words 18, "dix-huit"
23
+ expect_words 20, "vingt"
24
+ expect_words 21, "vingt et un"
25
+ expect_words 22, "vingt-deux"
26
+ expect_words 31, "trente et un"
27
+ expect_words 33, "trente-trois"
28
+ expect_words 44, "quarante-quatre"
29
+ expect_words 55, "cinquante-cinq"
30
+ expect_words 66, "soixante-six"
31
+ expect_words 70, "soixante-dix"
32
+ expect_words 71, "soixante et onze"
33
+ expect_words 72, "soixante-douze"
34
+ expect_words 73, "soixante-treize"
35
+ expect_words 79, "soixante-dix-neuf"
36
+ expect_words 80, "quatre-vingts"
37
+ expect_words 81, "quatre-vingt-un"
38
+ expect_words 82, "quatre-vingt-deux"
39
+ expect_words 83, "quatre-vingt-trois"
40
+ expect_words 89, "quatre-vingt-neuf"
41
+ expect_words 90, "quatre-vingt-dix"
42
+ expect_words 91, "quatre-vingt-onze"
43
+ expect_words 92, "quatre-vingt-douze"
44
+ expect_words 99, "quatre-vingt-dix-neuf"
45
+ expect_words 100, "cent"
46
+ expect_words 101, "cent un"
47
+ expect_words 110, "cent dix"
48
+ expect_words 111, "cent onze"
49
+ expect_words 119, "cent dix-neuf"
50
+ expect_words 120, "cent vingt"
51
+ expect_words 185, "cent quatre-vingt-cinq"
52
+ expect_words 300, "trois cents"
53
+ expect_words 301, "trois cent un"
54
+ expect_words 999, "neuf cent quatre-vingt-dix-neuf"
55
+ expect_words 1000, "mille"
56
+ expect_words 1001, "mille un"
57
+ expect_words 1002, "mille deux"
58
+ expect_words 1095, "mille quatre-vingt-quinze"
59
+ expect_words 1102, "mille cent deux"
60
+ expect_words 1199, "mille cent quatre-vingt-dix-neuf"
61
+ expect_words 1234, "mille deux cent trente-quatre"
62
+ expect_words 2001, "deux mille un"
63
+ expect_words 12001, "douze mille un"
64
+ expect_words 12345, "douze mille trois cent quarante-cinq"
65
+ expect_words 12500, "douze mille cinq cents"
66
+ expect_words 123456, "cent vingt-trois mille quatre cent cinquante-six"
67
+ expect_words 1234567, "un million deux cent trente-quatre mille cinq cent soixante-sept"
68
+ expect_words 9999999, "neuf millions neuf cent quatre-vingt-dix-neuf mille neuf cent quatre-vingt-dix-neuf"
69
+ expect_words 12345678, "douze millions trois cent quarante-cinq mille six cent soixante-dix-huit"
70
+ expect_words 999999999, "neuf cent quatre-vingt-dix-neuf millions neuf cent quatre-vingt-dix-neuf mille neuf cent quatre-vingt-dix-neuf"
71
+ expect_words 999999999999, "neuf cent quatre-vingt-dix-neuf milliards neuf cent quatre-vingt-dix-neuf millions neuf cent quatre-vingt-dix-neuf mille neuf cent quatre-vingt-dix-neuf"
72
+ end
73
+ end
@@ -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_fr
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: number_words
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: number_words handler for french
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_fr.rb
108
+ - lib/number_words_fr/version.rb
109
+ - lib/words.yml
110
+ - number_words_fr.gemspec
111
+ - spec/french_spec.rb
112
+ - spec/spec_helper.rb
113
+ homepage: https://github.com/conanite/number_words_fr
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: number_words handler for french
138
+ test_files:
139
+ - spec/french_spec.rb
140
+ - spec/spec_helper.rb