@pablobm commented on this pull request.
Thank you, so much better now, even if the logic is a bit cryptic to me 😅 The
important part is that now this is easily testable.
One detail is the commit structure. Ideally, we would want a commit for the
refactor (plus initial tests), then a commit for the new functionality (with
its own sets of tests). This way in the future someone reading through the
commits would understand the two different changes made here. Would you be able
to separate those?
> -# A map of each OSM key to its formatter URL. For example:
-# { "ref:vatin" => "https://example.com/$1" }
-# The JSON data is an array with duplicate entries, which is not efficient for
lookups.
-# So, convert it to a hash and only keep the item with the best rank.
-TAG2LINK = JSON.parse(Rails.root.join("node_modules/tag2link/index.json").read)
- # exclude deprecated and third-party URLs
- .reject { |item| item["rank"] == "deprecated" || item["source"]
== "wikidata:P3303" }
- .group_by { |item| item["key"] }
- .transform_keys { |key| key.sub(/^Key:/, "") }
- # move preferred to the start of the array
- .transform_values { |items| items.sort_by { |item| item["rank"]
== "preferred" ? 0 : 1 }.uniq { |item| item["url"] } }
- # exclude any that are ambiguous, i.e. the best and second-best
have the same rank
- .reject { |_key, value| value[1] && value[0]["rank"] ==
value[1]["rank"] }
- # keep only the best match
- .transform_values { |items| items[0]["url"] }
+require Rails.root.join("lib/tag2link")
No need for the absolute path. `lib/` is automatically in the library load path:
```suggestion
require "tag2link"
```
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/6470#pullrequestreview-3383236054
You are receiving this because you are subscribed to this thread.
Message ID:
<openstreetmap/openstreetmap-website/pull/6470/review/[email protected]>_______________________________________________
rails-dev mailing list
[email protected]
https://lists.openstreetmap.org/listinfo/rails-dev