Module: Snfn::Extensions::String

Defined in:
lib/extensions/string.rb

Instance Method Summary collapse

Instance Method Details

#camel_caseObject



4
5
6
7
8
9
10
11
12
# File 'lib/extensions/string.rb', line 4

def camel_case
  return self.gsub(/^./) { |l| l.capitalize } if !match(/[_-]/)
  altered_self = self.downcase.capitalize
  altered_self.scan(/[_-][a-zA-Z]/).each do |match|
    altered_self.gsub!(match, match[1].upcase)
  end

  altered_self
end

#camel_case!Object



14
15
16
# File 'lib/extensions/string.rb', line 14

def camel_case!
  self.replace camel_case
end

#file_nameObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/extensions/string.rb', line 18

def file_name
  return self.gsub(/-/, "_") if !match(/[A-Z]/)
  altered_self = self.strip

  altered_self.scan(/[A-Z]/).each do |match|
    altered_self.gsub!(match, "_#{match.downcase}")
  end

  altered_self.sub(/^_/, "").gsub(/_{2,}+/, "_").downcase
end

#file_name!Object



29
30
31
# File 'lib/extensions/string.rb', line 29

def file_name!
  self.replace file_name
end