Module: NidUtils::ClassMethods

Defined in:
lib/nid_utils.rb

Instance Method Summary collapse

Instance Method Details

#lower_case(text) ⇒ Object



81
82
83
84
# File 'lib/nid_utils.rb', line 81

def lower_case(text)
  return text unless present?(text)
  text.tr('ÅÄÖ', 'åäö').downcase
end

#nid_case(text) ⇒ Object



70
71
72
73
74
# File 'lib/nid_utils.rb', line 70

def nid_case(text)
  return text unless present?(text)
  text = normalize_chars(text)
  squish(lower_case(text).gsub('_','-').gsub(' ','-').gsub(UNWANTED_CHARACTERS_PATTERN, '').gsub(/-/, ' ')).gsub(/ /, '-')
end

#possible_nid?(candidate) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
79
# File 'lib/nid_utils.rb', line 76

def possible_nid?(candidate)
  return true if candidate.nil?
  !(candidate =~ UNWANTED_CHARACTERS_PATTERN)
end