Class: TeamApi::Canonicalizer
- Inherits:
-
Object
- Object
- TeamApi::Canonicalizer
- Defined in:
- lib/team_api/canonicalizer.rb
Overview
Contains utility functions for canonicalizing names and the order of data.
Class Method Summary collapse
-
.canonicalize(s) ⇒ Object
Returns a canonicalized, URL-friendly substitute for an arbitrary string.
-
.canonicalize_data(site_data) ⇒ Object
Canonicalizes the order and names of certain fields within site_data.
-
.hyphenate_yyyymmdd(timestamp) ⇒ Object
- Breaks a YYYYMMDD timestamp into a hyphenated version: YYYY-MM-DD
timestamp
-
timestamp in the form YYYYMMDD.
- Breaks a YYYYMMDD timestamp into a hyphenated version: YYYY-MM-DD
- .team_xrefs(team, usernames) ⇒ Object
Class Method Details
.canonicalize(s) ⇒ Object
Returns a canonicalized, URL-friendly substitute for an arbitrary string.
s
-
string to canonicalize
21 22 23 |
# File 'lib/team_api/canonicalizer.rb', line 21 def self.canonicalize(s) s.downcase.gsub(/\s+/, '-') unless s.nil? end |
.canonicalize_data(site_data) ⇒ Object
Canonicalizes the order and names of certain fields within site_data.
14 15 16 17 |
# 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) ⇒ Object
Breaks a YYYYMMDD timestamp into a hyphenated version: YYYY-MM-DD
timestamp
-
timestamp in the form YYYYMMDD
36 37 38 |
# File 'lib/team_api/canonicalizer.rb', line 36 def self.hyphenate_yyyymmdd() "#{[0..3]}-#{[4..5]}-#{[6..7]}" end |
.team_xrefs(team, usernames) ⇒ Object
25 26 27 28 29 30 31 32 |
# 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 |