Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/hiptest-publisher/string.rb

Instance Method Summary collapse

Instance Method Details

#camelizeObject



30
31
32
33
# File 'lib/hiptest-publisher/string.rb', line 30

def camelize
  normalized = self.normalize
  normalized.split('_').map {|w| w.empty? ? "" : "#{w[0].upcase}#{w[1..-1]}"}.join
end

#camelize_lowerObject



35
36
37
38
39
40
41
42
# File 'lib/hiptest-publisher/string.rb', line 35

def camelize_lower
  camelized = self.camelize
  if camelized.empty?
    ""
  else
    "#{camelized[0].downcase}#{camelized[1..-1]}"
  end
end

#camelize_upperObject



44
45
46
47
48
49
50
51
# File 'lib/hiptest-publisher/string.rb', line 44

def camelize_upper
  camelized = self.camelize
  if camelized.empty?
    ""
  else
    "#{camelized[0].upcase}#{camelized[1..-1]}"
  end
end

#clear_extensionObject



53
54
55
# File 'lib/hiptest-publisher/string.rb', line 53

def clear_extension
  self.split('.')[0]
end

#literateObject



6
7
8
9
# File 'lib/hiptest-publisher/string.rb', line 6

def literate
  I18n.enforce_available_locales = false
  I18n.transliterate(self)
end

#normalizeObject



11
12
13
14
# File 'lib/hiptest-publisher/string.rb', line 11

def normalize
  literated = self.literate
  literated.strip.gsub(/\s+/, '_').gsub(/\W/, '')
end

#normalize_lowerObject



16
17
18
# File 'lib/hiptest-publisher/string.rb', line 16

def normalize_lower
  self.normalize.downcase
end

#underscoreObject



20
21
22
23
24
25
26
27
28
# File 'lib/hiptest-publisher/string.rb', line 20

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').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').
    tr("-", "_").
    downcase
end