-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmethodDeclination.rb
More file actions
41 lines (35 loc) · 1.21 KB
/
methodDeclination.rb
File metadata and controls
41 lines (35 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Copyright (C) 2021-2026 my-app-s
# Licensed under the GNU AGPLv3
# Get the number from command line arguments.
# Defaults to 0 if no argument is provided.
total_number = ARGV[0].to_i
# Returns a string with the correctly declined noun based on the provided number.
#
# @param number [Integer] The number to determine the noun's form.
# @param form_one [String] Nominative singular (e.g., "crocodile").
# @param form_two [String] Genitive singular (e.g., "crocodiles" in some contexts).
# @param form_three [String] Genitive plural (e.g., "crocodiles").
#
# @return [String] A formatted string: "Number Noun!"
#
# @example
# declination(12, "apple", "apples", "apples") #=> "12 apples!"
#
def declination(number, form_one, form_two, form_three)
number = number.to_i
# Handle Russian language exceptions for numbers 11 to 14
if (number % 100).between?(11, 14)
return "#{number} #{form_three}!"
end
remainder = number % 10
case remainder
when 1
"#{number} #{form_one}!"
when 2..4
"#{number} #{form_two}!"
else
"#{number} #{form_three}!"
end
end
# Output the result to the console
puts declination(total_number, "crocodile", "crocodiles", "crocodiles")