Class: String

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

Instance Method Summary collapse

Instance Method Details

#camelizeObject



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

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

#camelize_lowerObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/hiptest-publisher/string.rb', line 36

def camelize_lower
  normalized = self.normalize
  normalized.split('_').enum_for(:each_with_index).map do |w, i|
    if w.empty?
      ""
    elsif i == 0
      "#{w[0].downcase}#{w[1..-1]}"
    else
      "#{w[0].upcase}#{w[1..-1]}"
    end
  end.join
end

#clear_extensionObject



49
50
51
# File 'lib/hiptest-publisher/string.rb', line 49

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
19
# File 'lib/hiptest-publisher/string.rb', line 16

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

#underscoreObject



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

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