Module: Num2words::Locales::JA
- Defined in:
- lib/num2words/locales/ja.rb
Constant Summary collapse
- ONES_MASC =
I18n.t("num2words.ones_masc", locale: :ja)
- ONES_FEM =
I18n.t("num2words.ones_fem", locale: :ja)
- TEENS =
I18n.t("num2words.teens", locale: :ja)
- TENS =
I18n.t("num2words.tens", locale: :ja)
- HUNDREDS =
I18n.t("num2words.hundreds", locale: :ja)
- SCALES =
I18n.t("num2words.scales", locale: :ja)
- FRACTIONS =
I18n.t("num2words.fractions", locale: :ja)
- GRAMMAR =
I18n.t("num2words.grammar", locale: :ja)
- DATE =
I18n.t("num2words.date", locale: :ja)
- DATE_TEMPLATE =
I18n.t("num2words.date.template", locale: :ja)
- TIME =
I18n.t("num2words.time", locale: :ja)
- TIME_TEMPLATE =
I18n.t("num2words.time.template", locale: :ja)
- DATETIME_TEMPLATE =
I18n.t("num2words.datetime.template", locale: :ja)
- ORDINALS =
I18n.t("num2words.numbers.ordinals", locale: :ja)
- THOUSANDS =
["", "せん", "にせん", "さんぜん", "よんせん", "ごせん", "ろくせん", "ななせん", "はっせん", "きゅうせん"].freeze
- LARGE_SCALES =
["", "まん", "おく", "ちょう", "けい"].freeze
Class Method Summary collapse
- .currency_major_feminine?(_currency) ⇒ Boolean
- .currency_minor_feminine?(_currency) ⇒ Boolean
- .currency_number_words(number, _currency, unit:) ⇒ Object
- .date_day(day, format: :default, date_case: :default) ⇒ Object
- .date_year(year, format: :default) ⇒ Object
- .decimal_fraction_words(fraction_string) ⇒ Object
- .decimal_separator_word ⇒ Object
- .default_fraction_word ⇒ Object
- .fraction_joiner(joiner) ⇒ Object
- .integer_to_words(number, feminine: false) ⇒ Object
- .join_currency_parts(parts) ⇒ Object
- .join_decimal_words(words) ⇒ Object
- .join_fraction_words(words) ⇒ Object
- .join_time_words(number_words, unit_words) ⇒ Object
- .minus_word ⇒ 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_ten_thousand(number) ⇒ Object
Class Method Details
.currency_major_feminine?(_currency) ⇒ Boolean
90 91 92 |
# File 'lib/num2words/locales/ja.rb', line 90 def currency_major_feminine?(_currency) false end |
.currency_minor_feminine?(_currency) ⇒ Boolean
94 95 96 |
# File 'lib/num2words/locales/ja.rb', line 94 def currency_minor_feminine?(_currency) false end |
.currency_number_words(number, _currency, unit:) ⇒ Object
98 99 100 |
# File 'lib/num2words/locales/ja.rb', line 98 def currency_number_words(number, _currency, unit:) integer_to_words(number) end |
.date_day(day, format: :default, date_case: :default) ⇒ Object
118 119 120 |
# File 'lib/num2words/locales/ja.rb', line 118 def date_day(day, format: :default, date_case: :default) integer_to_words(day) end |
.date_year(year, format: :default) ⇒ Object
122 123 124 |
# File 'lib/num2words/locales/ja.rb', line 122 def date_year(year, format: :default) integer_to_words(year) end |
.decimal_fraction_words(fraction_string) ⇒ Object
71 72 73 |
# File 'lib/num2words/locales/ja.rb', line 71 def decimal_fraction_words(fraction_string) fraction_string.chars.map { |digit| ONES_MASC[digit.to_i] }.join end |
.decimal_separator_word ⇒ Object
67 68 69 |
# File 'lib/num2words/locales/ja.rb', line 67 def decimal_separator_word GRAMMAR[:decimal_separator] || "てん" end |
.default_fraction_word ⇒ Object
63 64 65 |
# File 'lib/num2words/locales/ja.rb', line 63 def default_fraction_word GRAMMAR[:default_fraction] end |
.fraction_joiner(joiner) ⇒ Object
59 60 61 |
# File 'lib/num2words/locales/ja.rb', line 59 def fraction_joiner(joiner) joiner.to_sym == :and ? "と" : GRAMMAR[:conjunction] end |
.integer_to_words(number, feminine: false) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/num2words/locales/ja.rb', line 28 def integer_to_words(number, feminine: false) 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(4).map(&:reverse) .map(&:join).map!(&:to_i).reverse words = groups.each_with_index.filter_map do |group_value, index| next if group_value.zero? scale_index = groups.size - index - 1 "#{under_ten_thousand(group_value)}#{LARGE_SCALES.fetch(scale_index, '')}" end.join negative ? "#{minus_word}#{words}" : words end |
.join_currency_parts(parts) ⇒ Object
102 103 104 |
# File 'lib/num2words/locales/ja.rb', line 102 def join_currency_parts(parts) parts.join end |
.join_decimal_words(words) ⇒ Object
75 76 77 |
# File 'lib/num2words/locales/ja.rb', line 75 def join_decimal_words(words) words.compact.reject(&:empty?).join end |
.join_fraction_words(words) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/num2words/locales/ja.rb', line 79 def join_fraction_words(words) sign_word, integer_words, conjunction_word, numerator_words, denominator_words = words numerator_words = "" if denominator_words.to_s.end_with?(numerator_words.to_s) [sign_word, integer_words, conjunction_word, denominator_words, numerator_words].compact.reject(&:empty?).join end |
.join_time_words(number_words, unit_words) ⇒ Object
114 115 116 |
# File 'lib/num2words/locales/ja.rb', line 114 def join_time_words(number_words, unit_words) "#{number_words}#{unit_words}" end |
.minus_word ⇒ Object
55 56 57 |
# File 'lib/num2words/locales/ja.rb', line 55 def minus_word GRAMMAR[:minus] end |
.pluralize(number, singular, few, _plural) ⇒ Object
86 87 88 |
# File 'lib/num2words/locales/ja.rb', line 86 def pluralize(number, singular, few, _plural) number == 1 ? singular : few end |
.time_number_words(number, unit:) ⇒ Object
110 111 112 |
# File 'lib/num2words/locales/ja.rb', line 110 def time_number_words(number, unit:) integer_to_words(number) end |
.time_unit_feminine?(_unit) ⇒ Boolean
106 107 108 |
# File 'lib/num2words/locales/ja.rb', line 106 def time_unit_feminine?(_unit) false end |
.triple_to_words(number, scale_idx, feminine: false) ⇒ Object
49 50 51 52 53 |
# File 'lib/num2words/locales/ja.rb', line 49 def triple_to_words(number, scale_idx, feminine: false) words = under_ten_thousand(number) scale = LARGE_SCALES[scale_idx].to_s ["#{words}#{scale}"] end |
.under_hundred(number) ⇒ Object
139 140 141 142 143 144 145 146 147 |
# File 'lib/num2words/locales/ja.rb', line 139 def under_hundred(number) return "" if number.zero? return TEENS[number - 10] if number.between?(10, 19) tens = number / 10 ones = number % 10 [TENS[tens], ones.positive? ? ONES_MASC[ones] : nil].compact.reject(&:empty?).join end |
.under_ten_thousand(number) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/num2words/locales/ja.rb', line 126 def under_ten_thousand(number) thousands = number / 1000 remainder = number % 1000 hundreds = remainder / 100 rest = remainder % 100 [ THOUSANDS[thousands], HUNDREDS[hundreds], under_hundred(rest) ].compact.reject(&:empty?).join end |