Class: String

Inherits:
Object show all
Defined in:
lib/core_ext/string.rb,
lib/caricature/clr/aspnet_mvc.rb

Instance Method Summary collapse

Instance Method Details

#classifyObject

Gets the constant when it is defined that corresponds to this string



13
14
15
# File 'lib/core_ext/string.rb', line 13

def classify
  Object.const_get self
end

#to_qs_parametersObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/caricature/clr/aspnet_mvc.rb', line 16

def to_qs_parameters
  if self =~ /\?/
    parameters = NameValueCollection.new
    self.split('?')[1].split("&").each do |pair|
      parts = pair.split('=')
      parameters.add pair.first, pair.last
    end
    return parameters
  end
  nil
end

#to_url_filenameObject



11
12
13
14
# File 'lib/caricature/clr/aspnet_mvc.rb', line 11

def to_url_filename
  return self.gsub(/\?.*/, '') if self =~ /\?/
  self
end

#underscoreObject

converts a camel cased word to an underscored word



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

def underscore
  self.gsub(/::/, '/').
      gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
      gsub(/([a-z\d])([A-Z])/,'\1_\2').
      tr("-", "_").
      downcase
end