Module: Num2words::Locales::NL
- Defined in:
- lib/num2words/locales/nl.rb
Constant Summary collapse
- ONES_MASC =
I18n.t("num2words.ones_masc", locale: :nl)
- ONES_FEM =
I18n.t("num2words.ones_fem", locale: :nl)
- TEENS =
I18n.t("num2words.teens", locale: :nl)
- TENS =
I18n.t("num2words.tens", locale: :nl)
- HUNDREDS =
I18n.t("num2words.hundreds", locale: :nl)
- SCALES =
I18n.t("num2words.scales", locale: :nl)
- FRACTIONS =
I18n.t("num2words.fractions", locale: :nl)
- GRAMMAR =
I18n.t("num2words.grammar", locale: :nl)
- DATE =
I18n.t("num2words.date", locale: :nl)
- DATE_TEMPLATE =
I18n.t("num2words.date.template", locale: :nl)
- TIME =
I18n.t("num2words.time", locale: :nl)
- TIME_TEMPLATE =
I18n.t("num2words.time.template", locale: :nl)
- DATETIME_TEMPLATE =
I18n.t("num2words.datetime.template", locale: :nl)
- ORDINALS =
I18n.t("num2words.numbers.ordinals", locale: :nl)
Class Method Summary collapse
- .cardinal(number) ⇒ Object
- .compound_ones(number) ⇒ Object
- .currency_major_feminine?(_currency) ⇒ Boolean
- .currency_minor_feminine?(_currency) ⇒ Boolean
- .currency_number_words(number, _currency, unit:) ⇒ Object
- .date_day(day, format:, date_case:) ⇒ Object
- .date_year(year, format:) ⇒ Object
- .decimal_fraction_words(fraction_string) ⇒ Object
- .decimal_separator_word ⇒ Object
- .default_fraction_word ⇒ Object
- .fraction_joiner(joiner) ⇒ Object
- .fraction_numerator_feminine? ⇒ Boolean
- .integer_to_words(number, feminine: false) ⇒ Object
- .minus_word ⇒ Object
- .ordinal(value, format, gender: :masculine) ⇒ Object
- .pluralize(number, singular, few, plural) ⇒ Object
- .time_number_words(number, unit:) ⇒ Object
- .time_unit_feminine?(_unit) ⇒ Boolean
- .triple_to_words(number, scale_idx, feminine: false) ⇒ Object
- .under_hundred(number) ⇒ Object
- .under_thousand(number) ⇒ Object
Class Method Details
.cardinal(number) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/num2words/locales/nl.rb', line 99 def cardinal(number) integer_value = Integer(number) negative = integer_value.negative? integer_value = integer_value.abs return ONES_MASC[0] if integer_value.zero? groups = integer_value.to_s .chars.reverse.each_slice(3).map(&:reverse) .map(&:join).map!(&:to_i).reverse words = [] groups.each_with_index do |group_value, index| next if group_value.zero? scale_idx = groups.size - index - 1 group_words = triple_to_words(group_value, scale_idx) group_words.shift if scale_idx == 1 && group_value == 1 words.concat(group_words) end words.unshift(minus_word) if negative words.join(" ") end |
.compound_ones(number) ⇒ Object
144 145 146 147 148 149 150 |
# File 'lib/num2words/locales/nl.rb', line 144 def compound_ones(number) case number when 2 then "tweeën" when 3 then "drieën" else "#{ONES_MASC[number]}en" end end |
.currency_major_feminine?(_currency) ⇒ Boolean
78 79 80 |
# File 'lib/num2words/locales/nl.rb', line 78 def currency_major_feminine?(_currency) false end |
.currency_minor_feminine?(_currency) ⇒ Boolean
82 83 84 |
# File 'lib/num2words/locales/nl.rb', line 82 def currency_minor_feminine?(_currency) false end |
.currency_number_words(number, _currency, unit:) ⇒ Object
86 87 88 |
# File 'lib/num2words/locales/nl.rb', line 86 def currency_number_words(number, _currency, unit:) cardinal(number) end |
.date_day(day, format:, date_case:) ⇒ Object
62 63 64 |
# File 'lib/num2words/locales/nl.rb', line 62 def date_day(day, format:, date_case:) ordinal(day, :nominative) end |
.date_year(year, format:) ⇒ Object
66 67 68 |
# File 'lib/num2words/locales/nl.rb', line 66 def date_year(year, format:) cardinal(year) end |
.decimal_fraction_words(fraction_string) ⇒ Object
58 59 60 |
# File 'lib/num2words/locales/nl.rb', line 58 def decimal_fraction_words(fraction_string) fraction_string.chars.map { |digit| cardinal(digit.to_i) }.join(" ") end |
.decimal_separator_word ⇒ Object
54 55 56 |
# File 'lib/num2words/locales/nl.rb', line 54 def decimal_separator_word GRAMMAR[:conjunction] end |
.default_fraction_word ⇒ Object
46 47 48 |
# File 'lib/num2words/locales/nl.rb', line 46 def default_fraction_word GRAMMAR[:default_fraction] end |
.fraction_joiner(joiner) ⇒ Object
42 43 44 |
# File 'lib/num2words/locales/nl.rb', line 42 def fraction_joiner(joiner) joiner.to_sym == :and ? "en" : GRAMMAR[:conjunction] end |
.fraction_numerator_feminine? ⇒ Boolean
50 51 52 |
# File 'lib/num2words/locales/nl.rb', line 50 def fraction_numerator_feminine? false end |
.integer_to_words(number, feminine: false) ⇒ Object
26 27 28 |
# File 'lib/num2words/locales/nl.rb', line 26 def integer_to_words(number, feminine: false) cardinal(number) end |
.minus_word ⇒ Object
38 39 40 |
# File 'lib/num2words/locales/nl.rb', line 38 def minus_word GRAMMAR[:minus] end |
.ordinal(value, format, gender: :masculine) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/num2words/locales/nl.rb', line 90 def ordinal(value, format, gender: :masculine) ordinals = ORDINALS[format] || ORDINALS[:default] || ORDINALS[:nominative] gender_data = ordinals[gender] || ordinals[:masculine] return gender_data[value - 1] if value.between?(1, gender_data.length) cardinal(value) end |
.pluralize(number, singular, few, plural) ⇒ Object
152 153 154 |
# File 'lib/num2words/locales/nl.rb', line 152 def pluralize(number, singular, few, plural) number.abs == 1 ? singular : plural end |
.time_number_words(number, unit:) ⇒ Object
74 75 76 |
# File 'lib/num2words/locales/nl.rb', line 74 def time_number_words(number, unit:) cardinal(number) end |
.time_unit_feminine?(_unit) ⇒ Boolean
70 71 72 |
# File 'lib/num2words/locales/nl.rb', line 70 def time_unit_feminine?(_unit) false end |
.triple_to_words(number, scale_idx, feminine: false) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/num2words/locales/nl.rb', line 30 def triple_to_words(number, scale_idx, feminine: false) return [] if number.zero? words = [under_thousand(number)] words << pluralize(number, *SCALES[scale_idx]) unless scale_idx.zero? words end |
.under_hundred(number) ⇒ Object
134 135 136 137 138 139 140 141 142 |
# File 'lib/num2words/locales/nl.rb', line 134 def under_hundred(number) return ONES_MASC[number] if number < 10 return TEENS[number - 10] if number < 20 return TENS[number / 10] if (number % 10).zero? ones = compound_ones(number % 10) tens = TENS[number / 10] "#{ones}#{tens}" end |
.under_thousand(number) ⇒ Object
124 125 126 127 128 129 130 131 132 |
# File 'lib/num2words/locales/nl.rb', line 124 def under_thousand(number) return under_hundred(number) if number < 100 hundreds = number / 100 rest = number % 100 words = [HUNDREDS[hundreds]] words << under_hundred(rest) if rest.positive? words.join(" ") end |