class String

Public Instance Methods

camelize() click to toggle source
# File lib/hiptest-publisher/string.rb, line 54
def camelize
  normalized = self.normalize.split('_')
  normalized.map! {|w| w.empty? ? "" : "#{w[0].upcase}#{w[1..-1]}"}
  normalized.join
end
camelize_lower() click to toggle source
# File lib/hiptest-publisher/string.rb, line 60
def camelize_lower
  camelized = self.camelize
  if camelized.empty?
    ""
  else
    "#{camelized[0].downcase}#{camelized[1..-1]}"
  end
end
camelize_upper() click to toggle source
# File lib/hiptest-publisher/string.rb, line 69
def camelize_upper
  self.camelize
end
clear_extension() click to toggle source
# File lib/hiptest-publisher/string.rb, line 73
def clear_extension
  self.split('.')[0]
end
literate() click to toggle source
# File lib/hiptest-publisher/string.rb, line 6
def literate
  I18n.enforce_available_locales = false
  I18n.transliterate(self)
end
normalize(keep_dashes=false, keep_spaces=false) click to toggle source
# File lib/hiptest-publisher/string.rb, line 11
def normalize(keep_dashes=false, keep_spaces=false)
  literated = self.literate
  literated.strip!

  if keep_spaces
    literated.gsub!(/\s+/, ' ')
    literated.gsub!(/[^a-zA-Z0-9_\- "']/, '')
  else
    literated.gsub!(/\s+/, '_')
    if keep_dashes
      literated.gsub!(/[^a-zA-Z0-9_\-]/, '')
    else
      literated.gsub!(/\W/, '')
    end
  end
  literated
end
normalize_lower() click to toggle source
# File lib/hiptest-publisher/string.rb, line 29
def normalize_lower
  normalized = self.normalize
  normalized.downcase!
  normalized
end
normalize_with_dashes() click to toggle source
# File lib/hiptest-publisher/string.rb, line 35
def normalize_with_dashes
  self.normalize(true)
end
normalize_with_spaces() click to toggle source
# File lib/hiptest-publisher/string.rb, line 39
def normalize_with_spaces
  self.normalize(false, true)
end
underscore() click to toggle source
# File lib/hiptest-publisher/string.rb, line 43
def underscore
  # based on:
  # http://stackoverflow.com/questions/1509915/converting-camel-case-to-underscore-case-in-ruby
  normalized = self.normalize
  normalized.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
  normalized.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
  normalized.tr!("-", "_")
  normalized.downcase!
  normalized
end