Skip to content

Commit

Permalink
Remove remaining Unicode calls
Browse files Browse the repository at this point in the history
We can replace the unicode gem completely for Ruby 2.4+ by using the
core `#upcase` method which now has "Full Unicode case mapping" by
default [1].

[1] https://ruby-doc.org/core-2.4.0/String.html#method-i-downcase
  • Loading branch information
garethrees authored and gbp committed Oct 15, 2020
1 parent dd4397f commit 7fcf2b9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion app/controllers/public_body_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ def list
long_cache

@tag = params[:tag] || 'all'
@tag = Unicode.upcase(@tag) if @tag.scan(/./mu).size == 1
if @tag.scan(/./mu).size == 1
@tag = RUBY_VERSION < '2.4' ? Unicode.upcase(@tag) : @tag.upcase
end

@country_code = AlaveteliConfiguration.iso_country_code
@locale = AlaveteliLocalization.locale
Expand Down
4 changes: 3 additions & 1 deletion app/helpers/public_body_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ def type_of_authority(public_body)
types = categories.each_with_index.map do |category, index|
desc = category.description
if index.zero?
desc = desc.sub(/\S/) { |m| Unicode.upcase(m) }
desc = desc.sub(/\S/) do |m|
RUBY_VERSION < '2.4' ? Unicode.upcase(m) : m.upcase
end
end
link_to(desc, list_public_bodies_by_tag_path(category.category_tag))
end
Expand Down
6 changes: 5 additions & 1 deletion app/models/concerns/public_body_derived_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ def short_or_long_name
def set_first_letter
unless name.blank?
# we use a regex to ensure it works with utf-8/multi-byte
new_first_letter = Unicode.upcase name.scan(/^./mu)[0]
if RUBY_VERSION < '2.4'
new_first_letter = Unicode.upcase(name.scan(/^./mu)[0])
else
new_first_letter = name.scan(/^./mu)[0]&.upcase
end
if new_first_letter != first_letter
self.first_letter = new_first_letter
end
Expand Down

0 comments on commit 7fcf2b9

Please sign in to comment.