Module: Num2words::Locales::PL
- Defined in:
- lib/num2words/locales/pl.rb
Constant Summary collapse
- ONES_MASC =
I18n.t("num2words.ones_masc", locale: :pl)
- ONES_FEM =
I18n.t("num2words.ones_fem", locale: :pl)
- TEENS =
I18n.t("num2words.teens", locale: :pl)
- TENS =
I18n.t("num2words.tens", locale: :pl)
- HUNDREDS =
I18n.t("num2words.hundreds", locale: :pl)
- SCALES =
I18n.t("num2words.scales", locale: :pl)
- FRACTIONS =
I18n.t("num2words.fractions", locale: :pl)
- GRAMMAR =
I18n.t("num2words.grammar", locale: :pl)
- DATE =
I18n.t("num2words.date", locale: :pl)
- DATE_TEMPLATE =
I18n.t("num2words.date.template", locale: :pl)
- TIME =
I18n.t("num2words.time", locale: :pl)
- TIME_TEMPLATE =
I18n.t("num2words.time.template", locale: :pl)
- DATETIME_TEMPLATE =
I18n.t("num2words.datetime.template", locale: :pl)
- ORDINALS =
I18n.t("num2words.numbers.ordinals", locale: :pl)
- FEMININE_CURRENCIES =
%i[BDT CZK DKK IDR INR NOK PKR SEK TRY UAH].freeze
Class Method Summary collapse
- .cardinal(number, feminine: false) ⇒ 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
- .ordinal_compound(value, gender:) ⇒ 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
Class Method Details
.cardinal(number, feminine: false) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/num2words/locales/pl.rb', line 119 def cardinal(number, feminine: false) integer_value = Integer(number) negative = integer_value.negative? integer_value = integer_value.abs return (feminine ? ONES_FEM[0] : 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, feminine: feminine && scale_idx.zero?) group_words.shift if scale_idx == 1 && group_value == 1 words.concat(group_words) end words.unshift(minus_word) if negative words.join(" ") end |
.currency_major_feminine?(currency) ⇒ Boolean
97 98 99 |
# File 'lib/num2words/locales/pl.rb', line 97 def currency_major_feminine?(currency) FEMININE_CURRENCIES.include?(currency) end |
.currency_minor_feminine?(currency) ⇒ Boolean
101 102 103 |
# File 'lib/num2words/locales/pl.rb', line 101 def currency_minor_feminine?(currency) %i[BGN BYN RUB UAH].include?(currency) end |
.currency_number_words(number, currency, unit:) ⇒ Object
105 106 107 108 |
# File 'lib/num2words/locales/pl.rb', line 105 def currency_number_words(number, currency, unit:) feminine = unit == :major ? currency_major_feminine?(currency) : currency_minor_feminine?(currency) cardinal(number, feminine: feminine) end |
.date_day(day, format:, date_case:) ⇒ Object
75 76 77 |
# File 'lib/num2words/locales/pl.rb', line 75 def date_day(day, format:, date_case:) ordinal(day, :default) end |
.date_year(year, format:) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/num2words/locales/pl.rb', line 79 def date_year(year, format:) return ordinal(year, :default) if year <= 31 thousands = year / 1000 rest = year % 1000 words = [cardinal(thousands), pluralize(thousands, *SCALES[1])] words << ordinal(rest, :default) if rest.positive? words.join(" ") end |
.decimal_fraction_words(fraction_string) ⇒ Object
71 72 73 |
# File 'lib/num2words/locales/pl.rb', line 71 def decimal_fraction_words(fraction_string) fraction_string.chars.map { |digit| cardinal(digit.to_i) }.join(" ") end |
.decimal_separator_word ⇒ Object
67 68 69 |
# File 'lib/num2words/locales/pl.rb', line 67 def decimal_separator_word "przecinek" end |
.default_fraction_word ⇒ Object
59 60 61 |
# File 'lib/num2words/locales/pl.rb', line 59 def default_fraction_word GRAMMAR[:default_fraction] end |
.fraction_joiner(joiner) ⇒ Object
55 56 57 |
# File 'lib/num2words/locales/pl.rb', line 55 def fraction_joiner(joiner) joiner.to_sym == :and ? "i" : GRAMMAR[:conjunction] end |
.fraction_numerator_feminine? ⇒ Boolean
63 64 65 |
# File 'lib/num2words/locales/pl.rb', line 63 def fraction_numerator_feminine? true end |
.integer_to_words(number, feminine: false) ⇒ Object
28 29 30 |
# File 'lib/num2words/locales/pl.rb', line 28 def integer_to_words(number, feminine: false) cardinal(number, feminine: feminine) end |
.minus_word ⇒ Object
51 52 53 |
# File 'lib/num2words/locales/pl.rb', line 51 def minus_word GRAMMAR[:minus] end |
.ordinal(value, format, gender: :masculine) ⇒ Object
110 111 112 113 114 115 116 117 |
# File 'lib/num2words/locales/pl.rb', line 110 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) ordinal_compound(value, gender: gender) end |
.ordinal_compound(value, gender:) ⇒ Object
144 145 146 147 148 149 150 |
# File 'lib/num2words/locales/pl.rb', line 144 def ordinal_compound(value, gender:) base = value - (value % 100) rest = value % 100 return cardinal(value) if rest.zero? [cardinal(base), ordinal(rest, :default, gender: gender)].join(" ") end |
.pluralize(number, singular, few, plural) ⇒ Object
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/num2words/locales/pl.rb', line 152 def pluralize(number, singular, few, plural) number = number.abs return plural if (11..14).include?(number % 100) case number % 10 when 1 then number == 1 ? singular : plural when 2..4 then few else plural end end |
.time_number_words(number, unit:) ⇒ Object
93 94 95 |
# File 'lib/num2words/locales/pl.rb', line 93 def time_number_words(number, unit:) cardinal(number, feminine: true) end |
.time_unit_feminine?(_unit) ⇒ Boolean
89 90 91 |
# File 'lib/num2words/locales/pl.rb', line 89 def time_unit_feminine?(_unit) true end |
.triple_to_words(number, scale_idx, feminine: false) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/num2words/locales/pl.rb', line 32 def triple_to_words(number, scale_idx, feminine: false) return [] if number.zero? words = [] words << HUNDREDS[number / 100] if number >= 100 rest = number % 100 if rest.between?(10, 19) words << TEENS[rest - 10] else words << TENS[rest / 10] if rest >= 20 ones = rest % 10 words << (feminine ? ONES_FEM[ones] : ONES_MASC[ones]) if ones.positive? end words << pluralize(number, *SCALES[scale_idx]) unless scale_idx.zero? words.compact end |