This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git
The following commit(s) were added to refs/heads/master by this push:
new 1404fb7b helpers: improve class Integer function ordinalize (#217)
1404fb7b is described below
commit 1404fb7b4715bcf053636e95e2ab0d68da3d449b
Author: John Bampton <[email protected]>
AuthorDate: Sun Mar 24 09:39:22 2024 +1000
helpers: improve class Integer function ordinalize (#217)
---
www/board/agenda/helpers/integer.rb | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/www/board/agenda/helpers/integer.rb
b/www/board/agenda/helpers/integer.rb
index 8ce9e46f..fa582487 100644
--- a/www/board/agenda/helpers/integer.rb
+++ b/www/board/agenda/helpers/integer.rb
@@ -2,12 +2,15 @@
unless Integer.public_method_defined? :ordinalize
class Integer
def ordinalize
- if self % 10 == 1
- self.to_s + "st"
- elsif self % 10 == 2
- self.to_s + "nd"
+ case self % 100
+ when 11, 12, 13 then self.to_s + 'th'
else
- self.to_s + "th"
+ case self % 10
+ when 1 then self.to_s + 'st'
+ when 2 then self.to_s + 'nd'
+ when 3 then self.to_s + 'rd'
+ else self.to_s + 'th'
+ end
end
end
end