Module: Num2words::Locales::HU

Defined in:
lib/num2words/locales/hu.rb

Constant Summary collapse

ONES_MASC =
I18n.t("num2words.ones_masc", locale: :hu)
ONES_FEM =
I18n.t("num2words.ones_fem", locale: :hu)
TEENS =
I18n.t("num2words.teens", locale: :hu)
TENS =
I18n.t("num2words.tens", locale: :hu)
HUNDREDS =
I18n.t("num2words.hundreds", locale: :hu)
SCALES =
I18n.t("num2words.scales", locale: :hu)
FRACTIONS =
I18n.t("num2words.fractions", locale: :hu)
GRAMMAR =
I18n.t("num2words.grammar", locale: :hu)
DATE =
I18n.t("num2words.date", locale: :hu)
DATE_TEMPLATE =
I18n.t("num2words.date.template", locale: :hu)
TIME =
I18n.t("num2words.time", locale: :hu)
TIME_TEMPLATE =
I18n.t("num2words.time.template", locale: :hu)
DATETIME_TEMPLATE =
I18n.t("num2words.datetime.template", locale: :hu)
ORDINALS =
I18n.t("num2words.numbers.ordinals", locale: :hu)

Class Method Summary collapse

Class Method Details

.cardinal(number) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/num2words/locales/hu.rb', line 79

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
    words.concat triple_to_words(group_value, scale_idx)
  end

  words.unshift(minus_word) if negative
  words.join(" ")
end

.date_day(day, format:, date_case:) ⇒ Object



62
63
64
# File 'lib/num2words/locales/hu.rb', line 62

def date_day(day, format:, date_case:)
  ordinal(day, :default)
end

.date_year(year, format:) ⇒ Object



66
67
68
# File 'lib/num2words/locales/hu.rb', line 66

def date_year(year, format:)
  cardinal(year)
end

.decimal_fraction_words(fraction_string) ⇒ Object



58
59
60
# File 'lib/num2words/locales/hu.rb', line 58

def decimal_fraction_words(fraction_string)
  fraction_string.chars.map { |digit| cardinal(digit.to_i) }.join(" ")
end

.decimal_separator_wordObject



54
55
56
# File 'lib/num2words/locales/hu.rb', line 54

def decimal_separator_word
  "vessző"
end

.default_fraction_wordObject



46
47
48
# File 'lib/num2words/locales/hu.rb', line 46

def default_fraction_word
  GRAMMAR[:default_fraction]
end

.fraction_joiner(joiner) ⇒ Object



42
43
44
# File 'lib/num2words/locales/hu.rb', line 42

def fraction_joiner(joiner)
  joiner.to_sym == :and ? "és" : GRAMMAR[:conjunction]
end

.fraction_numerator_feminine?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/num2words/locales/hu.rb', line 50

def fraction_numerator_feminine?
  false
end

.integer_to_words(number, feminine: false) ⇒ Object



26
27
28
# File 'lib/num2words/locales/hu.rb', line 26

def integer_to_words(number, feminine: false)
  cardinal(number)
end

.minus_wordObject



38
39
40
# File 'lib/num2words/locales/hu.rb', line 38

def minus_word
  GRAMMAR[:minus]
end

.ordinal(value, format, gender: :masculine) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/num2words/locales/hu.rb', line 70

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



131
132
133
# File 'lib/num2words/locales/hu.rb', line 131

def pluralize(_number, singular, _few, _plural)
  singular
end

.tens_stem(tens) ⇒ Object



123
124
125
126
127
128
129
# File 'lib/num2words/locales/hu.rb', line 123

def tens_stem(tens)
  case tens
  when 2 then "huszon"
  when 3 then "harminc"
  else TENS[tens]
  end
end

.triple_to_words(number, scale_idx, feminine: false) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/num2words/locales/hu.rb', line 30

def triple_to_words(number, scale_idx, feminine: false)
  return [] if number.zero?

  words = [under_thousand(number)]
  words << SCALES[scale_idx][0] unless scale_idx.zero?
  words
end

.under_hundred(number) ⇒ Object



112
113
114
115
116
117
118
119
120
121
# File 'lib/num2words/locales/hu.rb', line 112

def under_hundred(number)
  return ONES_MASC[number] if number < 10
  return TEENS[number - 10] if number < 20

  tens = number / 10
  ones = number % 10
  return TENS[tens] if ones.zero?

  "#{tens_stem(tens)}#{ONES_MASC[ones]}"
end

.under_thousand(number) ⇒ Object



102
103
104
105
106
107
108
109
110
# File 'lib/num2words/locales/hu.rb', line 102

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