Class: TeamApi::TagCanonicalizer
- Inherits:
-
Object
- Object
- TeamApi::TagCanonicalizer
- Defined in:
- lib/team_api/tag_canonicalizer.rb
Overview
Contains utility functions for canonicalizing names and the order of data.
Class Method Summary collapse
- .canonicalize_categories(site_data, tag_categories) ⇒ Object
-
.canonicalize_tag_category(tags_xrefs) ⇒ Object
Consolidate tags entries that are not exactly the same.
- .canonicalize_tags_for_item(category, xrefs, item) ⇒ Object
Class Method Details
.canonicalize_categories(site_data, tag_categories) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# 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| category, xrefs, member end end end |
.canonicalize_tag_category(tags_xrefs) ⇒ Object
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.
23 24 25 26 27 28 29 |
# File 'lib/team_api/tag_canonicalizer.rb', line 23 def self.canonicalize_tag_category() return if .nil? || .empty? .replace(LambdaMapReduce.map_reduce( .values, ->(xref) { [[xref['slug'], xref]] }, method(:consolidate_xrefs)).to_h) end |
.canonicalize_tags_for_item(category, xrefs, item) ⇒ Object
41 42 43 44 45 |
# File 'lib/team_api/tag_canonicalizer.rb', line 41 def self.(category, xrefs, item) return if item[category].nil? item[category].each { |tag| tag['name'] = xrefs[tag['slug']]['name'] } .sort_by! { |tag| tag['name'] } end |