numbers_and_words 0.11.0 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/numbers_and_words/core_ext/array.rb +2 -2
- data/lib/numbers_and_words/core_ext/float.rb +1 -1
- data/lib/numbers_and_words/core_ext/integer.rb +1 -1
- data/lib/numbers_and_words/helper_classes.rb +1 -1
- data/lib/numbers_and_words/helper_classes/array_extensions/helpers.rb +11 -12
- data/lib/numbers_and_words/helper_classes/figures_array.rb +1 -4
- data/lib/numbers_and_words/helper_classes/words_array.rb +2 -4
- data/lib/numbers_and_words/i18n.rb +4 -4
- data/lib/numbers_and_words/i18n/initialization.rb +2 -2
- data/lib/numbers_and_words/i18n/locales/numbers.en.yml +3 -3
- data/lib/numbers_and_words/i18n/locales/numbers.es.yml +86 -25
- data/lib/numbers_and_words/i18n/locales/numbers.fr.yml +54 -1
- data/lib/numbers_and_words/i18n/locales/numbers.pt-BR.yml +4 -4
- data/lib/numbers_and_words/i18n/locales/numbers.pt.yml +0 -1
- data/lib/numbers_and_words/i18n/pluralization.rb +2 -3
- data/lib/numbers_and_words/i18n/plurals/fr.rb +3 -3
- data/lib/numbers_and_words/i18n/plurals/lt.rb +11 -8
- data/lib/numbers_and_words/i18n/plurals/lv.rb +3 -3
- data/lib/numbers_and_words/i18n/plurals/ru.rb +15 -10
- data/lib/numbers_and_words/strategies.rb +1 -1
- data/lib/numbers_and_words/strategies/array_joiner.rb +1 -2
- data/lib/numbers_and_words/strategies/array_joiner/languages.rb +3 -1
- data/lib/numbers_and_words/strategies/array_joiner/languages/base.rb +1 -1
- data/lib/numbers_and_words/strategies/array_joiner/languages/es.rb +10 -0
- data/lib/numbers_and_words/strategies/array_joiner/languages/families/base.rb +0 -1
- data/lib/numbers_and_words/strategies/array_joiner/languages/fr.rb +10 -0
- data/lib/numbers_and_words/strategies/figures_converter.rb +1 -2
- data/lib/numbers_and_words/strategies/figures_converter/decorators.rb +8 -6
- data/lib/numbers_and_words/strategies/figures_converter/decorators/base.rb +2 -2
- data/lib/numbers_and_words/strategies/figures_converter/decorators/en/base.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/decorators/en/fractional.rb +2 -3
- data/lib/numbers_and_words/strategies/figures_converter/decorators/en/integral.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/decorators/es.rb +3 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/es/base.rb +12 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/es/fractional.rb +38 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/es/integral.rb +12 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/fr.rb +3 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/fr/base.rb +12 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/fr/fractional.rb +37 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/fr/integral.rb +12 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/hu.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/decorators/hu/base.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/decorators/hu/fractional.rb +2 -3
- data/lib/numbers_and_words/strategies/figures_converter/decorators/hu/integral.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/decorators/pt-BR/fractional.rb +1 -2
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ru/base.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ru/fractional.rb +2 -3
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ru/integral.rb +1 -2
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ua/base.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ua/fractional.rb +2 -3
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ua/integral.rb +1 -2
- data/lib/numbers_and_words/strategies/figures_converter/languages.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/languages/base.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/languages/de.rb +9 -9
- data/lib/numbers_and_words/strategies/figures_converter/languages/en-GB.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/languages/en.rb +17 -19
- data/lib/numbers_and_words/strategies/figures_converter/languages/es.rb +50 -25
- data/lib/numbers_and_words/strategies/figures_converter/languages/et.rb +1 -2
- data/lib/numbers_and_words/strategies/figures_converter/languages/families/base.rb +5 -5
- data/lib/numbers_and_words/strategies/figures_converter/languages/families/cyrillic.rb +5 -5
- data/lib/numbers_and_words/strategies/figures_converter/languages/families/helpers.rb +10 -14
- data/lib/numbers_and_words/strategies/figures_converter/languages/fr.rb +7 -7
- data/lib/numbers_and_words/strategies/figures_converter/languages/hu.rb +8 -8
- data/lib/numbers_and_words/strategies/figures_converter/languages/ka.rb +8 -10
- data/lib/numbers_and_words/strategies/figures_converter/languages/lt.rb +6 -6
- data/lib/numbers_and_words/strategies/figures_converter/languages/lv.rb +2 -2
- data/lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb +24 -26
- data/lib/numbers_and_words/strategies/figures_converter/languages/pt.rb +6 -7
- data/lib/numbers_and_words/strategies/figures_converter/languages/tr.rb +4 -4
- data/lib/numbers_and_words/strategies/figures_converter/options.rb +6 -5
- data/lib/numbers_and_words/strategies/figures_converter/options/en-GB/hundreds_with_union.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/options/en-GB/ordinal.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/options/en-GB/remove_hyphen.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/options/en-GB/remove_zero.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/options/en/hundreds_with_union.rb +3 -3
- data/lib/numbers_and_words/strategies/figures_converter/options/en/ordinal.rb +3 -3
- data/lib/numbers_and_words/strategies/figures_converter/options/en/pronounced.rb +14 -23
- data/lib/numbers_and_words/strategies/figures_converter/options/en/remove_hyphen.rb +2 -3
- data/lib/numbers_and_words/strategies/figures_converter/options/en/remove_zero.rb +2 -2
- data/lib/numbers_and_words/strategies/figures_converter/options/es.rb +3 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/es/apocopated.rb +28 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/es/gender.rb +28 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/es/remove_zero.rb +28 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/hu/ordinal.rb +3 -3
- data/lib/numbers_and_words/strategies/figures_converter/options/pt-BR/gender.rb +2 -2
- data/lib/numbers_and_words/strategies/figures_converter/options/pt-BR/ordinal.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/options/pt-BR/remove_zero.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/options/ru/gender.rb +2 -2
- data/lib/numbers_and_words/strategies/figures_converter/options/ua/gender.rb +2 -2
- data/lib/numbers_and_words/translations/base.rb +2 -2
- data/lib/numbers_and_words/translations/de.rb +5 -5
- data/lib/numbers_and_words/translations/es.rb +29 -24
- data/lib/numbers_and_words/translations/et.rb +3 -3
- data/lib/numbers_and_words/translations/extensions/fraction_significance.rb +4 -5
- data/lib/numbers_and_words/translations/families/base.rb +8 -8
- data/lib/numbers_and_words/translations/families/cyrillic.rb +6 -6
- data/lib/numbers_and_words/translations/families/latin.rb +6 -6
- data/lib/numbers_and_words/translations/fr.rb +16 -8
- data/lib/numbers_and_words/translations/hu.rb +3 -3
- data/lib/numbers_and_words/translations/it.rb +3 -3
- data/lib/numbers_and_words/translations/ka.rb +13 -13
- data/lib/numbers_and_words/translations/lt.rb +4 -5
- data/lib/numbers_and_words/translations/lv.rb +4 -5
- data/lib/numbers_and_words/translations/nl.rb +3 -3
- data/lib/numbers_and_words/translations/pt-BR.rb +18 -18
- data/lib/numbers_and_words/translations/pt.rb +4 -5
- data/lib/numbers_and_words/translations/ru.rb +5 -5
- data/lib/numbers_and_words/translations/se.rb +2 -2
- data/lib/numbers_and_words/translations/tr.rb +3 -4
- data/lib/numbers_and_words/translations/ua.rb +3 -3
- data/lib/numbers_and_words/version.rb +1 -1
- data/lib/numbers_and_words/wrappers.rb +1 -1
- data/lib/numbers_and_words/wrappers/float.rb +9 -9
- data/lib/numbers_and_words/wrappers/integer.rb +3 -3
- metadata +16 -4
- data/lib/numbers_and_words/helper_classes/array_extensions/validations.rb +0 -19
- data/lib/numbers_and_words/i18n/plurals/pt-BR.rb +0 -15
@@ -2,11 +2,11 @@ module NumbersAndWords
|
|
2
2
|
module I18n
|
3
3
|
module Plurals
|
4
4
|
module Fr
|
5
|
-
|
5
|
+
module_function
|
6
6
|
|
7
|
-
|
7
|
+
RULE = ->(n) { one_conditions(n) ? :one : :other }
|
8
8
|
|
9
|
-
def one_conditions
|
9
|
+
def one_conditions(n)
|
10
10
|
n % 10 == 1 && n % 100 != 11
|
11
11
|
end
|
12
12
|
end
|
@@ -2,23 +2,26 @@ module NumbersAndWords
|
|
2
2
|
module I18n
|
3
3
|
module Plurals
|
4
4
|
module Lt
|
5
|
+
module_function
|
6
|
+
|
5
7
|
RULE = lambda do |n|
|
6
|
-
|
7
|
-
:one
|
8
|
-
|
8
|
+
if one_conditions(n)
|
9
|
+
:one
|
10
|
+
elsif ones_conditions(n)
|
11
|
+
:ones
|
12
|
+
else
|
13
|
+
:other
|
14
|
+
end
|
9
15
|
end
|
10
16
|
|
11
|
-
|
12
|
-
|
13
|
-
def one_conditions n
|
17
|
+
def one_conditions(n)
|
14
18
|
n % 10 == 1 && n % 100 != 11
|
15
19
|
end
|
16
20
|
|
17
|
-
def ones_conditions
|
21
|
+
def ones_conditions(n)
|
18
22
|
[2, 3, 4, 5, 6, 7, 8, 9].include?(n % 10) && ![12, 13, 14, 15, 16, 17, 18, 19].include?(n % 100)
|
19
23
|
end
|
20
24
|
end
|
21
25
|
end
|
22
26
|
end
|
23
27
|
end
|
24
|
-
|
@@ -2,11 +2,11 @@ module NumbersAndWords
|
|
2
2
|
module I18n
|
3
3
|
module Plurals
|
4
4
|
module Lv
|
5
|
-
|
5
|
+
module_function
|
6
6
|
|
7
|
-
|
7
|
+
RULE = ->(n) { one_conditions(n) ? :one : :other }
|
8
8
|
|
9
|
-
def one_conditions
|
9
|
+
def one_conditions(n)
|
10
10
|
n % 10 == 1 && n % 100 != 11
|
11
11
|
end
|
12
12
|
end
|
@@ -2,25 +2,30 @@ module NumbersAndWords
|
|
2
2
|
module I18n
|
3
3
|
module Plurals
|
4
4
|
module Ru
|
5
|
+
module_function
|
6
|
+
|
5
7
|
RULE = lambda do |n|
|
6
|
-
|
7
|
-
:one
|
8
|
-
|
9
|
-
|
8
|
+
if one_conditions(n)
|
9
|
+
:one
|
10
|
+
elsif few_conditions(n)
|
11
|
+
:few
|
12
|
+
elsif many_conditions(n)
|
13
|
+
:many
|
14
|
+
else
|
15
|
+
:other
|
16
|
+
end
|
10
17
|
end
|
11
18
|
|
12
|
-
|
13
|
-
|
14
|
-
def one_conditions n
|
19
|
+
def one_conditions(n)
|
15
20
|
n % 10 == 1 && n % 100 != 11
|
16
21
|
end
|
17
22
|
|
18
|
-
def few_conditions
|
23
|
+
def few_conditions(n)
|
19
24
|
[2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100)
|
20
25
|
end
|
21
26
|
|
22
|
-
def many_conditions
|
23
|
-
n % 10
|
27
|
+
def many_conditions(n)
|
28
|
+
(n % 10).zero? || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100)
|
24
29
|
end
|
25
30
|
end
|
26
31
|
end
|
@@ -4,10 +4,9 @@ module NumbersAndWords
|
|
4
4
|
module Strategies
|
5
5
|
module ArrayJoiner
|
6
6
|
class Base
|
7
|
-
|
8
7
|
attr_accessor :options, :elements, :translations, :language
|
9
8
|
|
10
|
-
def initialize
|
9
|
+
def initialize(elements, options = {})
|
11
10
|
@elements = elements
|
12
11
|
@options = options
|
13
12
|
@translations = Translations.factory
|
@@ -4,6 +4,8 @@ require 'numbers_and_words/strategies/array_joiner/languages/base'
|
|
4
4
|
|
5
5
|
require 'numbers_and_words/strategies/array_joiner/languages/en'
|
6
6
|
require 'numbers_and_words/strategies/array_joiner/languages/en-GB'
|
7
|
+
require 'numbers_and_words/strategies/array_joiner/languages/es'
|
8
|
+
require 'numbers_and_words/strategies/array_joiner/languages/fr'
|
7
9
|
require 'numbers_and_words/strategies/array_joiner/languages/hu'
|
8
10
|
require 'numbers_and_words/strategies/array_joiner/languages/ru'
|
9
11
|
require 'numbers_and_words/strategies/array_joiner/languages/ua'
|
@@ -14,7 +16,7 @@ module NumbersAndWords
|
|
14
16
|
module ArrayJoiner
|
15
17
|
module Languages
|
16
18
|
class << self
|
17
|
-
def factory
|
19
|
+
def factory(strategy)
|
18
20
|
Object.const_get("#{name}::#{I18n.language_class_name}").new strategy
|
19
21
|
end
|
20
22
|
end
|
@@ -6,10 +6,9 @@ module NumbersAndWords
|
|
6
6
|
module Strategies
|
7
7
|
module FiguresConverter
|
8
8
|
class Base
|
9
|
-
|
10
9
|
attr_accessor :options, :figures, :translations, :language, :decorator
|
11
10
|
|
12
|
-
def initialize
|
11
|
+
def initialize(figures, options = {})
|
13
12
|
@figures = figures.reverse
|
14
13
|
|
15
14
|
@decorator = Decorators.factory(self, options)
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'numbers_and_words/strategies/figures_converter/decorators/base'
|
2
2
|
require 'numbers_and_words/strategies/figures_converter/decorators/en'
|
3
3
|
require 'numbers_and_words/strategies/figures_converter/decorators/en-GB'
|
4
|
+
require 'numbers_and_words/strategies/figures_converter/decorators/es'
|
5
|
+
require 'numbers_and_words/strategies/figures_converter/decorators/fr'
|
4
6
|
require 'numbers_and_words/strategies/figures_converter/decorators/ru'
|
5
7
|
require 'numbers_and_words/strategies/figures_converter/decorators/pt-BR'
|
6
8
|
require 'numbers_and_words/strategies/figures_converter/decorators/hu'
|
@@ -11,23 +13,23 @@ module NumbersAndWords
|
|
11
13
|
module FiguresConverter
|
12
14
|
module Decorators
|
13
15
|
class << self
|
14
|
-
AVAILABLE = [
|
16
|
+
AVAILABLE = %i[integral fractional].freeze
|
15
17
|
|
16
|
-
def factory
|
18
|
+
def factory(strategy, options)
|
17
19
|
enabled_decorator(options).new strategy, options
|
18
20
|
end
|
19
21
|
|
20
22
|
private
|
21
23
|
|
22
|
-
def enabled_decorator
|
23
|
-
decorator_class AVAILABLE.
|
24
|
+
def enabled_decorator(options)
|
25
|
+
decorator_class AVAILABLE.reject { |name| options[name].nil? }.first
|
24
26
|
end
|
25
27
|
|
26
|
-
def decorator_class
|
28
|
+
def decorator_class(method_name)
|
27
29
|
method_name ? Object.const_get(decorator_class_name(method_name)) : Decorators::Base
|
28
30
|
end
|
29
31
|
|
30
|
-
def decorator_class_name
|
32
|
+
def decorator_class_name(method_name)
|
31
33
|
"#{name}::#{I18n.language_class_name}::#{method_name.to_s.split('_').collect(&:capitalize).join}"
|
32
34
|
end
|
33
35
|
end
|
@@ -3,7 +3,7 @@ module NumbersAndWords
|
|
3
3
|
module FiguresConverter
|
4
4
|
module Decorators
|
5
5
|
class Base
|
6
|
-
def initialize
|
6
|
+
def initialize(strategy, options)
|
7
7
|
@strategy = strategy
|
8
8
|
@options = options
|
9
9
|
end
|
@@ -15,4 +15,4 @@ module NumbersAndWords
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
|
-
end
|
18
|
+
end
|
@@ -4,7 +4,6 @@ module NumbersAndWords
|
|
4
4
|
module Decorators
|
5
5
|
module En
|
6
6
|
class Fractional < Base
|
7
|
-
|
8
7
|
def run
|
9
8
|
"#{super} #{fraction_significance}"
|
10
9
|
end
|
@@ -16,7 +15,7 @@ module NumbersAndWords
|
|
16
15
|
end
|
17
16
|
|
18
17
|
def full_fraction
|
19
|
-
(0..zero_length).inject(figures.clone) { |result,
|
18
|
+
(0..zero_length).inject(figures.clone) { |result, _el| result.unshift 0 }.to_figures
|
20
19
|
end
|
21
20
|
|
22
21
|
def figures
|
@@ -35,4 +34,4 @@ module NumbersAndWords
|
|
35
34
|
end
|
36
35
|
end
|
37
36
|
end
|
38
|
-
end
|
37
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module NumbersAndWords
|
2
|
+
module Strategies
|
3
|
+
module FiguresConverter
|
4
|
+
module Decorators
|
5
|
+
module Es
|
6
|
+
class Fractional < Base
|
7
|
+
def run
|
8
|
+
@options[:gender] = :female
|
9
|
+
"#{super} #{fraction_significance}"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def fraction_significance
|
15
|
+
@strategy.translations.micros full_fraction.fraction_capacity, figures.join.to_i
|
16
|
+
end
|
17
|
+
|
18
|
+
def full_fraction
|
19
|
+
(0..zero_length).inject(figures.clone) { |result, _el| result.unshift 0 }.to_figures
|
20
|
+
end
|
21
|
+
|
22
|
+
def figures
|
23
|
+
@strategy.figures
|
24
|
+
end
|
25
|
+
|
26
|
+
def zero_length
|
27
|
+
fraction_length - figures.length
|
28
|
+
end
|
29
|
+
|
30
|
+
def fraction_length
|
31
|
+
@options[:fractional][:length].to_i
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module NumbersAndWords
|
2
|
+
module Strategies
|
3
|
+
module FiguresConverter
|
4
|
+
module Decorators
|
5
|
+
module Fr
|
6
|
+
class Fractional < Base
|
7
|
+
def run
|
8
|
+
"#{super} #{fraction_significance}"
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def fraction_significance
|
14
|
+
@strategy.translations.micros full_fraction.fraction_capacity, figures.join.to_i
|
15
|
+
end
|
16
|
+
|
17
|
+
def full_fraction
|
18
|
+
(0..zero_length).inject(figures.clone) { |result, _el| result.unshift 0 }.to_figures
|
19
|
+
end
|
20
|
+
|
21
|
+
def figures
|
22
|
+
@strategy.figures.reverse
|
23
|
+
end
|
24
|
+
|
25
|
+
def zero_length
|
26
|
+
fraction_length - figures.length
|
27
|
+
end
|
28
|
+
|
29
|
+
def fraction_length
|
30
|
+
@options[:fractional][:length].to_i
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
1
|
require 'numbers_and_words/strategies/figures_converter/decorators/hu/base'
|
2
2
|
require 'numbers_and_words/strategies/figures_converter/decorators/hu/fractional'
|
3
|
-
require 'numbers_and_words/strategies/figures_converter/decorators/hu/integral'
|
3
|
+
require 'numbers_and_words/strategies/figures_converter/decorators/hu/integral'
|