Election results in the London Borough of Sutton.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

helpers.rb 1.3 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. class String
  2. def pluralize(num)
  3. if num == 1
  4. return self
  5. end
  6. case self[-1]
  7. when 'y'
  8. self[0..-2] + 'ies'
  9. when 's'
  10. self + "es"
  11. else
  12. self + "s"
  13. end
  14. end
  15. end
  16. def commify(num)
  17. num.to_s.reverse.gsub(/(\d\d\d)(?=\d)(?!\d*\.)/,'\1,').reverse
  18. end
  19. # From http://snippets.dzone.com/posts/show/593
  20. def to_ordinal(num)
  21. num = num.to_i
  22. if (10...20) === num
  23. "#{num}th"
  24. else
  25. g = %w{ th st nd rd th th th th th th }
  26. a = num.to_s
  27. c = a[-1..-1].to_i
  28. a + g[c]
  29. end
  30. end
  31. def format_percent(num)
  32. sprintf("%.0f%%", num)
  33. end
  34. def short_date(d)
  35. # FIXME wtf - because sometimes we're doing raw sql queries and sometimes it's coming through the DataMapper::Resource class
  36. d = Date.parse(d) unless d.class == Date
  37. d.strftime("%e %b %Y")
  38. end
  39. def long_date(d)
  40. # FIXME wtf - because sometimes we're doing raw sql queries and sometimes it's coming through the DataMapper::Resource class
  41. d = Date.parse(d) unless d.class == Date
  42. d.strftime("%e %B %Y")
  43. end
  44. # Exception for Labour/Co-operative candidacies
  45. def party_name(labcoop, party_name)
  46. # puts labcoop.class # FIXME wtf - because sometimes we're doing raw sql queries and sometimes it's coming through the DataMapper::Resource class
  47. labcoop == 1 || labcoop == '1' ? "Labour and Co-operative Party" : party_name
  48. end