]> git.openstreetmap.org Git - rails.git/blobdiff - lib/short_link.rb
Merge remote-tracking branch 'upstream/pull/5717'
[rails.git] / lib / short_link.rb
index 424e85c1095999e781147f35610193b36ade59e0..eb73d60290701656749df8598a15cdbc8cbb1d00 100644 (file)
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 ##
 # Encodes and decodes locations from Morton-coded "quad tile" strings. Each
 # variable-length string encodes to a precision of one pixel per tile (roughly,
@@ -23,7 +25,7 @@ module ShortLink
       # keep support for old shortlinks which use the @ character, now
       # replaced by the ~ character because twitter is horribly broken
       # and we can't have that.
-      str.tr!("@", "~")
+      str = str.tr("@", "~")
 
       str.each_char do |c|
         t = ARRAY.index c
@@ -32,11 +34,11 @@ module ShortLink
         else
           3.times do
             x <<= 1
-            x |= 1 unless (t & 32).zero?
+            x |= 1 unless t.nobits?(32)
             t <<= 1
 
             y <<= 1
-            y |= 1 unless (t & 32).zero?
+            y |= 1 unless t.nobits?(32)
             t <<= 1
           end
           z += 3
@@ -57,7 +59,7 @@ module ShortLink
     def encode(lon, lat, z)
       code = interleave_bits(((lon + 180.0) * (2**32) / 360.0).to_i,
                              ((lat + 90.0) * (2**32) / 180.0).to_i)
-      str = ""
+      str = +""
       # add eight to the zoom level, which approximates an accuracy of
       # one pixel in a tile.
       ((z + 8) / 3.0).ceil.times do |i|