class TeamApi::Canonicalizer

Contains utility functions for canonicalizing names and the order of data.

Public Class Methods

canonicalize(s) click to toggle source

Returns a canonicalized, URL-friendly substitute for an arbitrary string.

s

string to canonicalize

# File lib/team_api/canonicalizer.rb, line 21
def self.canonicalize(s)
  s.downcase.gsub(/\s+/, '-') unless s.nil?
end
canonicalize_data(site_data) click to toggle source

Canonicalizes the order and names of certain fields within site_data.

# File lib/team_api/canonicalizer.rb, line 14
def self.canonicalize_data(site_data)
  CollectionCanonicalizer.sort_collections site_data
  TagCanonicalizer.canonicalize_categories site_data, %w(skills interests)
end
hyphenate_yyyymmdd(timestamp) click to toggle source

Breaks a YYYYMMDD timestamp into a hyphenated version: YYYY-MM-DD

timestamp

timestamp in the form YYYYMMDD

# File lib/team_api/canonicalizer.rb, line 36
def self.hyphenate_yyyymmdd(timestamp)
  "#{timestamp[0..3]}-#{timestamp[4..5]}-#{timestamp[6..7]}"
end
team_xrefs(team, usernames) click to toggle source
# File lib/team_api/canonicalizer.rb, line 25
def self.team_xrefs(team, usernames)
  fields = CrossReferencer::TEAM_FIELDS
  result = usernames
    .map { |username| team[username] }
    .compact
    .map { |member| member.select { |field, _| fields.include? field } }
  NameCanonicalizer.sort_by_last_name result
end