numbers_and_words 0.5.0 → 0.6.0
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.
- checksums.yaml +15 -0
- data/README.rdoc +90 -1
- data/lib/numbers_and_words.rb +4 -3
- data/lib/numbers_and_words/core_ext.rb +1 -0
- data/lib/numbers_and_words/core_ext/array.rb +1 -1
- data/lib/numbers_and_words/core_ext/float.rb +5 -0
- data/lib/numbers_and_words/core_ext/integer.rb +2 -9
- data/lib/numbers_and_words/helper_classes.rb +2 -0
- data/lib/numbers_and_words/helper_classes/array_extensions/helpers.rb +81 -0
- data/lib/numbers_and_words/helper_classes/array_extensions/validations.rb +19 -0
- data/lib/numbers_and_words/helper_classes/figures_array.rb +18 -0
- data/lib/numbers_and_words/helper_classes/words_array.rb +11 -0
- data/lib/numbers_and_words/i18n/locales/numbers.en.yml +48 -0
- data/lib/numbers_and_words/i18n/locales/numbers.es.yml +15 -0
- data/lib/numbers_and_words/i18n/locales/numbers.hu.yml +16 -0
- data/lib/numbers_and_words/i18n/locales/numbers.ru.yml +27 -3
- data/lib/numbers_and_words/i18n/locales/numbers.se.yml +7 -0
- data/lib/numbers_and_words/i18n/locales/numbers.ua.yml +14 -2
- data/lib/numbers_and_words/i18n/pluralization.rb +1 -0
- data/lib/numbers_and_words/i18n/plurals/es.rb +11 -0
- data/lib/numbers_and_words/strategies.rb +16 -11
- data/lib/numbers_and_words/strategies/array_joiner.rb +31 -0
- data/lib/numbers_and_words/strategies/figures_converter.rb +33 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators.rb +39 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/base.rb +18 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/en.rb +3 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/en/base.rb +12 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/en/fractional.rb +38 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/en/integral.rb +12 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/hu.rb +3 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/hu/base.rb +12 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/hu/fractional.rb +38 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/hu/integral.rb +12 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ru.rb +3 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ru/base.rb +12 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ru/fractional.rb +39 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ru/integral.rb +27 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ua.rb +3 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ua/base.rb +12 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ua/fractional.rb +39 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ua/integral.rb +27 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages.rb +39 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/base.rb +29 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/en.rb +48 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/es.rb +37 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/families/base.rb +77 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/families/cyrillic.rb +34 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/families/helpers.rb +36 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/families/latin.rb +13 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/fr.rb +37 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/hu.rb +63 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/it.rb +11 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/nl.rb +26 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/ru.rb +11 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/se.rb +11 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/tr.rb +11 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/ua.rb +11 -0
- data/lib/numbers_and_words/strategies/figures_converter/options.rb +41 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/en.rb +4 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/en/hundreds_with_union.rb +33 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/en/ordinal.rb +60 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/en/remove_hyphen.rb +29 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/en/remove_zero.rb +29 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/hu.rb +1 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/hu/ordinal.rb +60 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/ru.rb +1 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/ru/gender.rb +28 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/ua.rb +1 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/ua/gender.rb +28 -0
- data/lib/numbers_and_words/translations.rb +25 -0
- data/lib/numbers_and_words/{translations_helpers → translations}/base.rb +2 -2
- data/lib/numbers_and_words/translations/en.rb +8 -0
- data/lib/numbers_and_words/translations/es.rb +37 -0
- data/lib/numbers_and_words/translations/extensions/fraction_significance.rb +25 -0
- data/lib/numbers_and_words/translations/families/base.rb +33 -0
- data/lib/numbers_and_words/translations/families/cyrillic.rb +29 -0
- data/lib/numbers_and_words/translations/families/latin.rb +23 -0
- data/lib/numbers_and_words/translations/fr.rb +29 -0
- data/lib/numbers_and_words/translations/hu.rb +26 -0
- data/lib/numbers_and_words/translations/it.rb +15 -0
- data/lib/numbers_and_words/translations/nl.rb +15 -0
- data/lib/numbers_and_words/translations/ru.rb +25 -0
- data/lib/numbers_and_words/translations/se.rb +11 -0
- data/lib/numbers_and_words/translations/tr.rb +11 -0
- data/lib/numbers_and_words/translations/ua.rb +21 -0
- data/lib/numbers_and_words/version.rb +1 -1
- data/lib/numbers_and_words/wrappers.rb +2 -0
- data/lib/numbers_and_words/wrappers/float.rb +60 -0
- data/lib/numbers_and_words/wrappers/integer.rb +21 -0
- metadata +81 -44
- data/lib/numbers_and_words/array_additions.rb +0 -2
- data/lib/numbers_and_words/array_additions/helpers.rb +0 -44
- data/lib/numbers_and_words/array_additions/validations.rb +0 -9
- data/lib/numbers_and_words/figures_array.rb +0 -15
- data/lib/numbers_and_words/strategies/base.rb +0 -18
- data/lib/numbers_and_words/strategies/en.rb +0 -8
- data/lib/numbers_and_words/strategies/families/base.rb +0 -71
- data/lib/numbers_and_words/strategies/families/cyrillic.rb +0 -18
- data/lib/numbers_and_words/strategies/families/latin.rb +0 -9
- data/lib/numbers_and_words/strategies/fr.rb +0 -32
- data/lib/numbers_and_words/strategies/it.rb +0 -8
- data/lib/numbers_and_words/strategies/nl.rb +0 -23
- data/lib/numbers_and_words/strategies/ru.rb +0 -8
- data/lib/numbers_and_words/strategies/tr.rb +0 -8
- data/lib/numbers_and_words/strategies/ua.rb +0 -8
- data/lib/numbers_and_words/translations_helpers.rb +0 -11
- data/lib/numbers_and_words/translations_helpers/en.rb +0 -12
- data/lib/numbers_and_words/translations_helpers/families/base.rb +0 -30
- data/lib/numbers_and_words/translations_helpers/families/cyrillic.rb +0 -28
- data/lib/numbers_and_words/translations_helpers/families/latin.rb +0 -23
- data/lib/numbers_and_words/translations_helpers/fr.rb +0 -34
- data/lib/numbers_and_words/translations_helpers/it.rb +0 -16
- data/lib/numbers_and_words/translations_helpers/nl.rb +0 -18
- data/lib/numbers_and_words/translations_helpers/ru.rb +0 -8
- data/lib/numbers_and_words/translations_helpers/tr.rb +0 -8
- data/lib/numbers_and_words/translations_helpers/ua.rb +0 -8
@@ -0,0 +1,37 @@
|
|
1
|
+
module NumbersAndWords
|
2
|
+
module Strategies
|
3
|
+
module FiguresConverter
|
4
|
+
module Languages
|
5
|
+
class Fr < Base
|
6
|
+
include Families::Latin
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def capacity_iteration
|
11
|
+
words = []
|
12
|
+
capacity_words = words_in_capacity(@current_capacity)
|
13
|
+
words.push(megs) unless capacity_words.empty?
|
14
|
+
words += capacity_words unless is_a_thousand? and is_a_one?
|
15
|
+
words
|
16
|
+
end
|
17
|
+
|
18
|
+
def is_a_one?
|
19
|
+
[translations.ones(1)] == words_in_capacity(@current_capacity)
|
20
|
+
end
|
21
|
+
|
22
|
+
def is_a_thousand?
|
23
|
+
FiguresArray::THOUSAND_CAPACITY == @current_capacity
|
24
|
+
end
|
25
|
+
|
26
|
+
def hundreds
|
27
|
+
super({:pluralize => simple_number_to_words.empty?})
|
28
|
+
end
|
29
|
+
|
30
|
+
def megs
|
31
|
+
super({:number => @figures.number_in_capacity(@current_capacity)})
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module NumbersAndWords
|
2
|
+
module Strategies
|
3
|
+
module FiguresConverter
|
4
|
+
module Languages
|
5
|
+
class Hu < Base
|
6
|
+
include Families::Latin
|
7
|
+
|
8
|
+
def print_words
|
9
|
+
inner_reverse_words.reverse.join(greater_than_2000? && '-' || '')
|
10
|
+
end
|
11
|
+
|
12
|
+
def inner_reverse_words
|
13
|
+
@strings.collect { |iteration| iteration.reverse.join }
|
14
|
+
end
|
15
|
+
|
16
|
+
def greater_than_2000?
|
17
|
+
@figures.length > 4 || (@figures.length == 4 && @figures.last >= 2)
|
18
|
+
end
|
19
|
+
|
20
|
+
def strings_logic
|
21
|
+
if @figures.capacity_count
|
22
|
+
number_without_capacity_to_words + complex_number_to_words
|
23
|
+
elsif @figures.hundreds
|
24
|
+
[hundreds_number_to_words]
|
25
|
+
elsif @figures.tens or @figures.ones
|
26
|
+
[simple_number_to_words]
|
27
|
+
else
|
28
|
+
[]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def complex_number_to_words
|
33
|
+
count = @figures.capacity_count
|
34
|
+
(1..count).map { |capacity|
|
35
|
+
@current_capacity = capacity
|
36
|
+
capacity_iteration.flatten
|
37
|
+
}.reject(&:empty?)
|
38
|
+
end
|
39
|
+
|
40
|
+
def simple_number_to_words
|
41
|
+
if @figures.teens || @figures.tens
|
42
|
+
[complex_tens]
|
43
|
+
elsif @figures.ones
|
44
|
+
[ones]
|
45
|
+
else
|
46
|
+
[]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
[:zero, :ones, :teens, :tens, :tens_with_ones, :hundreds, :megs].each do |method_name|
|
51
|
+
define_method(method_name) {
|
52
|
+
super({:prefix => maybe_ordinal(method_name)})
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def maybe_ordinal type
|
57
|
+
@options.ordinal.result type
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module NumbersAndWords
|
2
|
+
module Strategies
|
3
|
+
module FiguresConverter
|
4
|
+
module Languages
|
5
|
+
class Nl < Base
|
6
|
+
include Families::Latin
|
7
|
+
|
8
|
+
def hundreds_number_to_words
|
9
|
+
[super.reverse.join]
|
10
|
+
end
|
11
|
+
|
12
|
+
def capacity_iteration
|
13
|
+
if FiguresArray::THOUSAND_CAPACITY == @current_capacity
|
14
|
+
words = []
|
15
|
+
capacity_words = words_in_capacity(@current_capacity)
|
16
|
+
words.push megs unless capacity_words.empty?
|
17
|
+
capacity_words.empty? ? [] : [capacity_words, words].join
|
18
|
+
else
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'numbers_and_words/strategies/figures_converter/options/en'
|
2
|
+
require 'numbers_and_words/strategies/figures_converter/options/ru'
|
3
|
+
require 'numbers_and_words/strategies/figures_converter/options/ua'
|
4
|
+
require 'numbers_and_words/strategies/figures_converter/options/hu'
|
5
|
+
|
6
|
+
module NumbersAndWords
|
7
|
+
module Strategies
|
8
|
+
module FiguresConverter
|
9
|
+
module Options
|
10
|
+
class Proxy
|
11
|
+
attr_accessor :strategy, :options
|
12
|
+
|
13
|
+
def initialize strategy, options
|
14
|
+
@strategy = strategy
|
15
|
+
@options = options
|
16
|
+
end
|
17
|
+
|
18
|
+
def method_missing method_name, *args, &block
|
19
|
+
proxy_class_name(method_name).constantize.new self, args, block
|
20
|
+
rescue NameError
|
21
|
+
return nil
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def proxy_class_name method_name
|
27
|
+
"#{module_name}::#{language_class_name}::#{method_name.to_s.camelcase}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def language_class_name
|
31
|
+
::I18n.locale.to_s.titleize.gsub ' ', '::'
|
32
|
+
end
|
33
|
+
|
34
|
+
def module_name
|
35
|
+
self.class.name.split('::')[0..-2].join '::'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,4 @@
|
|
1
|
+
require 'numbers_and_words/strategies/figures_converter/options/en/hundreds_with_union'
|
2
|
+
require 'numbers_and_words/strategies/figures_converter/options/en/remove_hyphen'
|
3
|
+
require 'numbers_and_words/strategies/figures_converter/options/en/ordinal'
|
4
|
+
require 'numbers_and_words/strategies/figures_converter/options/en/remove_zero'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module NumbersAndWords
|
2
|
+
module Strategies
|
3
|
+
module FiguresConverter
|
4
|
+
module Options
|
5
|
+
module En
|
6
|
+
class HundredsWithUnion
|
7
|
+
attr_accessor :strategy, :options
|
8
|
+
|
9
|
+
def initialize proxy, *args, &block
|
10
|
+
@strategy = proxy.strategy
|
11
|
+
@options = proxy.options
|
12
|
+
end
|
13
|
+
|
14
|
+
def modify_or_leave hundreds
|
15
|
+
hundreds = "#{hundreds} #{translations.union}" if active?
|
16
|
+
hundreds
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def active?
|
22
|
+
@options[:hundreds_with_union]
|
23
|
+
end
|
24
|
+
|
25
|
+
def translations
|
26
|
+
@strategy.translations
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module NumbersAndWords
|
2
|
+
module Strategies
|
3
|
+
module FiguresConverter
|
4
|
+
module Options
|
5
|
+
module En
|
6
|
+
class Ordinal
|
7
|
+
ZERO_TYPE = :zero
|
8
|
+
HUNDRED_TYPE = :hundreds
|
9
|
+
MEGS_TYPE = :megs
|
10
|
+
|
11
|
+
def initialize proxy, *args, &block
|
12
|
+
@strategy = proxy.strategy
|
13
|
+
@options = proxy.options
|
14
|
+
end
|
15
|
+
|
16
|
+
def result type
|
17
|
+
@type = type
|
18
|
+
MEGS_TYPE != type ? check_simple_numbers : check_megs_numbers
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def active?
|
24
|
+
@options[:ordinal]
|
25
|
+
end
|
26
|
+
|
27
|
+
def check_simple_numbers
|
28
|
+
:ordinal if simple_numbers_condition && active?
|
29
|
+
end
|
30
|
+
|
31
|
+
def check_megs_numbers
|
32
|
+
:ordinal if megs_numbers_condition && active?
|
33
|
+
end
|
34
|
+
|
35
|
+
def simple_numbers_condition
|
36
|
+
current_capacity.nil? &&
|
37
|
+
(HUNDRED_TYPE != @type || (HUNDRED_TYPE == @type && simple_number_to_words.empty?))
|
38
|
+
end
|
39
|
+
|
40
|
+
def megs_numbers_condition
|
41
|
+
current_capacity == language_figures.ordinal_capacity
|
42
|
+
end
|
43
|
+
|
44
|
+
def simple_number_to_words
|
45
|
+
@strategy.language.simple_number_to_words
|
46
|
+
end
|
47
|
+
|
48
|
+
def current_capacity
|
49
|
+
@strategy.language.current_capacity
|
50
|
+
end
|
51
|
+
|
52
|
+
def language_figures
|
53
|
+
@strategy.language.parent_figures
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module NumbersAndWords
|
2
|
+
module Strategies
|
3
|
+
module FiguresConverter
|
4
|
+
module Options
|
5
|
+
module En
|
6
|
+
class RemoveHyphen
|
7
|
+
attr_accessor :strategy, :options
|
8
|
+
|
9
|
+
def initialize proxy, *args, &block
|
10
|
+
@strategy = proxy.strategy
|
11
|
+
@options = proxy.options
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def result
|
16
|
+
active? ? ' ' : '-'
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def active?
|
22
|
+
@options[:remove_hyphen]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module NumbersAndWords
|
2
|
+
module Strategies
|
3
|
+
module FiguresConverter
|
4
|
+
module Options
|
5
|
+
module En
|
6
|
+
class RemoveZero
|
7
|
+
attr_accessor :strategy, :options
|
8
|
+
|
9
|
+
def initialize proxy, *args, &block
|
10
|
+
@strategy = proxy.strategy
|
11
|
+
@options = proxy.options
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def result
|
16
|
+
active?
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def active?
|
22
|
+
@options[:remove_zero]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'numbers_and_words/strategies/figures_converter/options/hu/ordinal'
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module NumbersAndWords
|
2
|
+
module Strategies
|
3
|
+
module FiguresConverter
|
4
|
+
module Options
|
5
|
+
module Hu
|
6
|
+
class Ordinal
|
7
|
+
ZERO_TYPE = :zero
|
8
|
+
HUNDRED_TYPE = :hundreds
|
9
|
+
MEGS_TYPE = :megs
|
10
|
+
|
11
|
+
def initialize proxy, *args, &block
|
12
|
+
@strategy = proxy.strategy
|
13
|
+
@options = proxy.options
|
14
|
+
end
|
15
|
+
|
16
|
+
def result type
|
17
|
+
@type = type
|
18
|
+
MEGS_TYPE != type ? check_simple_numbers : check_megs_numbers
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def active?
|
24
|
+
@options[:ordinal]
|
25
|
+
end
|
26
|
+
|
27
|
+
def check_simple_numbers
|
28
|
+
:ordinal if simple_numbers_condition && active?
|
29
|
+
end
|
30
|
+
|
31
|
+
def check_megs_numbers
|
32
|
+
:ordinal if megs_numbers_condition && active?
|
33
|
+
end
|
34
|
+
|
35
|
+
def simple_numbers_condition
|
36
|
+
current_capacity.nil? &&
|
37
|
+
(HUNDRED_TYPE != @type || (HUNDRED_TYPE == @type && simple_number_to_words.empty?))
|
38
|
+
end
|
39
|
+
|
40
|
+
def megs_numbers_condition
|
41
|
+
current_capacity == language_figures.ordinal_capacity
|
42
|
+
end
|
43
|
+
|
44
|
+
def simple_number_to_words
|
45
|
+
@strategy.language.simple_number_to_words
|
46
|
+
end
|
47
|
+
|
48
|
+
def current_capacity
|
49
|
+
@strategy.language.current_capacity
|
50
|
+
end
|
51
|
+
|
52
|
+
def language_figures
|
53
|
+
@strategy.language.parent_figures
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|