Module: Atlasq::Util::String

Defined in:
lib/atlasq/util/string.rb

Constant Summary collapse

ABBREVIATIONS =
{
  "AMER" => "North, Central and South America",
  "APAC" => "Asia-Pacific",
  "EMEA" => "Europe, Middle East, and Africa",
}.freeze

Class Method Summary collapse

Class Method Details

.normalize(string) ⇒ String

Make string lowercase and remove accents.

Parameters:

Returns:



38
39
40
41
# File 'lib/atlasq/util/string.rb', line 38

def self.normalize(string)
  @normalize ||= {}
  @normalize[string] ||= Unaccent.unaccent(string.downcase)
end

.titleize(string) ⇒ String

Parameters:

Returns:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/atlasq/util/string.rb', line 16

def self.titleize(string)
  abbreviation = string.upcase

  if (full_name = ABBREVIATIONS[abbreviation])
    "#{full_name} (#{abbreviation})"
  else
    words = string.split(/[-_ \t]+/)
    words.map! do |word|
      if word.match?(/^(?:of|the|and)$/i)
        word.downcase
      else
        word.capitalize
      end
    end
    words.join(" ")
  end
end

.word_split(sentence) ⇒ Array<String>

Split on spaces, tabs and punctuation separators. Note: Some punctuation can be connectors or separators based on the language.

Parameters:

Returns:



48
49
50
# File 'lib/atlasq/util/string.rb', line 48

def self.word_split(sentence)
  sentence.split(/[ \t,;:()]+/).reject(&:empty?)
end