Class: String

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

Instance Method Summary collapse

Instance Method Details

#camel_caseObject



3
4
5
6
# File 'lib/string.rb', line 3

def camel_case
  str = upper_camel_case
  return str[0,1].downcase + str[1, str.length]
end

#pluralizeObject



23
24
25
26
27
# File 'lib/string.rb', line 23

def pluralize
#  TODO: replace with call to Inflector.pluralize
  return self + 's' if self[length-1, length] != 's'
  return self + 'es' if self[length-1, length] == 's'
end

#to_bObject



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

def to_b
  self == 'true'
end

#to_nObject



33
34
35
# File 'lib/string.rb', line 33

def to_n
  return Rogdl::Node.new(self)
end

#upper_camel_caseObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/string.rb', line 8

def upper_camel_case
  str = self
  
  str.gsub!(/-/,"_")
  str.gsub!(/ /,"_")
  str.gsub!(/[^a-zA-Z0-9_\- ]/,"_")
  str = "_" + str.split.join("_")
  str.gsub!(/_(.)/) { $1.upcase }
  
  return str

end