Module: Num2words::Locales::MS

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

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.cardinal(number) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/num2words/locales/ms.rb', line 100

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

.currency_major_feminine?(_currency) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/num2words/locales/ms.rb', line 79

def currency_major_feminine?(_currency)
  false
end

.currency_minor_feminine?(_currency) ⇒ Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/num2words/locales/ms.rb', line 83

def currency_minor_feminine?(_currency)
  false
end

.currency_number_words(number, _currency, unit:) ⇒ Object



87
88
89
# File 'lib/num2words/locales/ms.rb', line 87

def currency_number_words(number, _currency, unit:)
  cardinal(number)
end

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



63
64
65
# File 'lib/num2words/locales/ms.rb', line 63

def date_day(day, format:, date_case:)
  cardinal(day)
end

.date_year(year, format:) ⇒ Object



67
68
69
# File 'lib/num2words/locales/ms.rb', line 67

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

.decimal_fraction_words(fraction_string) ⇒ Object



59
60
61
# File 'lib/num2words/locales/ms.rb', line 59

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

.decimal_separator_wordObject



55
56
57
# File 'lib/num2words/locales/ms.rb', line 55

def decimal_separator_word
  GRAMMAR[:conjunction]
end

.default_fraction_wordObject



47
48
49
# File 'lib/num2words/locales/ms.rb', line 47

def default_fraction_word
  GRAMMAR[:default_fraction]
end

.fraction_joiner(joiner) ⇒ Object



43
44
45
# File 'lib/num2words/locales/ms.rb', line 43

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

.fraction_numerator_feminine?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/num2words/locales/ms.rb', line 51

def fraction_numerator_feminine?
  false
end

.integer_to_words(number, feminine: false) ⇒ Object



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

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

.minus_wordObject



39
40
41
# File 'lib/num2words/locales/ms.rb', line 39

def minus_word
  GRAMMAR[:minus]
end

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



91
92
93
94
95
96
97
98
# File 'lib/num2words/locales/ms.rb', line 91

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



144
145
146
# File 'lib/num2words/locales/ms.rb', line 144

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

.time_number_words(number, unit:) ⇒ Object



75
76
77
# File 'lib/num2words/locales/ms.rb', line 75

def time_number_words(number, unit:)
  cardinal(number)
end

.time_unit_feminine?(_unit) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/num2words/locales/ms.rb', line 71

def time_unit_feminine?(_unit)
  false
end

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



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

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

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

.under_hundred(number) ⇒ Object



133
134
135
136
137
138
139
140
141
142
# File 'lib/num2words/locales/ms.rb', line 133

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

  tens = number / 10
  ones = number % 10
  words = ["#{ONES_MASC[tens]} puluh"]
  words << ONES_MASC[ones] if ones.positive?
  words.join(" ")
end

.under_thousand(number) ⇒ Object



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

def under_thousand(number)
  return under_hundred(number) if number < 100

  hundreds = number / 100
  rest = number % 100
  words = [hundreds == 1 ? "seratus" : "#{ONES_MASC[hundreds]} ratus"]
  words << under_hundred(rest) if rest.positive?
  words.join(" ")
end