Module: AWSCronParser::Helpers::Numbers
- Defined in:
- lib/aws_cron_parser/helpers/numbers.rb
Instance Method Summary collapse
-
#ordinal(num) ⇒ Object
Convert number to ordinal string (1 => "1st", 2 => "2nd", etc.).
-
#ordinal_word(num) ⇒ Object
Convert number to ordinal word (1 => "first", 2 => "second", etc.).
Instance Method Details
#ordinal(num) ⇒ Object
Convert number to ordinal string (1 => "1st", 2 => "2nd", etc.)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/aws_cron_parser/helpers/numbers.rb', line 7 def ordinal(num) num = num.to_i case num % 100 when 11, 12, 13 "#{num}th" else case num % 10 when 1 then "#{num}st" when 2 then "#{num}nd" when 3 then "#{num}rd" else "#{num}th" end end end |
#ordinal_word(num) ⇒ Object
Convert number to ordinal word (1 => "first", 2 => "second", etc.)
23 24 25 26 27 28 29 |
# File 'lib/aws_cron_parser/helpers/numbers.rb', line 23 def ordinal_word(num) num = num.to_i words = %w[zeroth first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth thirteenth fourteenth fifteenth sixteenth seventeenth eighteenth nineteenth twentieth] words[num] || ordinal(num).to_s end |