aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
authorGareth Rees <gareth@mysociety.org>2015-01-23 15:12:50 +0000
committerGareth Rees <gareth@mysociety.org>2015-02-04 15:02:00 +0000
commit93c137a906715c194dc64044556c148d813c87a3 (patch)
treec7479f296aa16b9eb50a0bcea6edd08daa5104dc /app/models
parent3fe8f773df749988a1d88141330e65b13eb43ab6 (diff)
Nicer capitalize first letter only
String#capitalize downcases remaining letters, so: > 'heLLo WorLd'.capitalize # => "Hello world" Our version only works on the first character of the String, preserving the case of the rest of the String: > 'heLLo WorLd'.sub(/\S/) { |m| Unicode.upcase(m) } # => 'HeLLo WorLd' Also handle unicode.
Diffstat (limited to 'app/models')
-rw-r--r--app/models/public_body.rb9
1 files changed, 4 insertions, 5 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index f6d182878..ee38a7269 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -341,12 +341,11 @@ class PublicBody < ActiveRecord::Base
tags.each do |tag|
if PublicBodyCategory.get().by_tag().include?(tag.name)
desc = PublicBodyCategory.get().singular_by_tag()[tag.name]
- if first
- # terrible that Ruby/Rails doesn't have an equivalent of ucfirst
- # (capitalize shockingly converts later characters to lowercase)
- desc = desc[0,1].capitalize + desc[1,desc.size]
- first = false
+
+ if index.zero?
+ desc = desc.sub(/\S/) { |m| Unicode.upcase(m) }
end
+
if html
# TODO: this should call proper route helpers, but is in model sigh
desc = '<a href="/body/list/' + tag.name + '">' + desc + '</a>'