class TeamApi::TagCanonicalizer
Contains utility functions for canonicalizing names and the order of data.
Public Class Methods
canonicalize_categories(site_data, tag_categories)
click to toggle source
# File lib/team_api/tag_canonicalizer.rb, line 8 def self.canonicalize_categories(site_data, tag_categories) tag_categories.each do |category| xrefs = site_data[category] canonicalize_tag_category xrefs site_data['team'].values.each do |member| canonicalize_tags_for_item category, xrefs, member end end end
canonicalize_tag_category(tags_xrefs)
click to toggle source
Consolidate tags entries that are not exactly the same. Selects the lexicographically smaller version of the tag as a standard.
In the future, we may just consider raising an error if there are two different strings for the same thing.
# File lib/team_api/tag_canonicalizer.rb, line 23 def self.canonicalize_tag_category(tags_xrefs) return if tags_xrefs.nil? || tags_xrefs.empty? tags_xrefs.replace(LambdaMapReduce.map_reduce( tags_xrefs.values, ->(xref) { [[xref['slug'], xref]] }, method(:consolidate_xrefs)).to_h) end
Private Class Methods
consolidate_xrefs(slug, xrefs)
click to toggle source
# File lib/team_api/tag_canonicalizer.rb, line 31 def self.consolidate_xrefs(slug, xrefs) xrefs.sort_by! { |xref| xref['name'] } result = xrefs.each_with_object(xrefs.shift) do |xref, consolidated| consolidated['members'].concat xref['members'] end NameCanonicalizer.sort_by_last_name! result['members'] [slug, result] end