Module: Kabal::DeutschRules::NaturalNumbers

Included in:
Kabal::Deutsch
Defined in:
lib/kabal/languages/deutsch/natural_numbers.rb

Instance Method Summary collapse

Instance Method Details

#count_name(number) ⇒ Object



51
52
53
# File 'lib/kabal/languages/deutsch/natural_numbers.rb', line 51

def count_name(number)
  three_words count(number)
end

#create_number_name(number) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/kabal/languages/deutsch/natural_numbers.rb', line 43

def create_number_name(number)
  if @number_name.nil?
    @number_name = words_to_add(number)
  elsif count(number) != 0
    @number_name += words_to_add(number)
  end
end

#less_thousands(number) ⇒ Object



55
56
57
58
# File 'lib/kabal/languages/deutsch/natural_numbers.rb', line 55

def less_thousands(number)
  return if number == 0
  @number_name += three_words(number % 1000) unless number == 0
end

#millions_or_greater?(number) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/kabal/languages/deutsch/natural_numbers.rb', line 60

def millions_or_greater?(number)
  number_order(number) > 3
end

#natural_number_name(number) ⇒ Object



4
5
6
7
8
9
# File 'lib/kabal/languages/deutsch/natural_numbers.rb', line 4

def natural_number_name(number)
  return single number if number >= 0 and number <= 19
  return two_words number if number >= 0 and number <= 99
  return three_words number if number >= 100 and number <= 999
  ten_powers number if number >= 100
end

#single(number) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/kabal/languages/deutsch/natural_numbers.rb', line 10

def single(number)
  unless @ein
    names["single"][number]
  else
    @ein = false
    names["single"][number].chop
  end
end

#ten_powers(number) ⇒ Object



36
37
38
39
40
41
# File 'lib/kabal/languages/deutsch/natural_numbers.rb', line 36

def ten_powers(number)
  less_thousands number if number_is_thousands? number
  return @number_name if number_is_thousands? number
  create_number_name number
  ten_powers number % (10 ** number_order(number))
end

#three_words(number) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/kabal/languages/deutsch/natural_numbers.rb', line 27

def three_words(number)
  return two_words number if number <= 99
  @ein = (number / 100 == 1)
  number_name = single(number / 100) + names["ten_powers"][2]
  number_name += two_words(number % 100) if (number % 100 >= 10)
  number_name += single(number % 100) if number % 100 < 10 and number % 100 != 0
  number_name
end

#two_words(number) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/kabal/languages/deutsch/natural_numbers.rb', line 19

def two_words(number)
  return single number if number <= 19
  number_name = names["two_words"][number / 10]
  @ein = (number % 10 == 1)
  number_name = single(number % 10) + names["and"] + number_name if (number % 10 != 0)
  number_name
end

#words_to_add(number) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/kabal/languages/deutsch/natural_numbers.rb', line 64

def words_to_add(number)
  if millions_or_greater?(number)
    @number_name = count_name(number) + " " + Declinations.name_with_declination(names["ten_powers"][number_order(number)], count(number)) + " "
  else
    @number_name = count_name(number) + Declinations.name_with_declination(names["ten_powers"][number_order(number)], count(number))
  end
end