Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
# File lib/deltacloud/core_ext/string.rb, line 22 def blank? self !~ %r\S/ end
# File lib/deltacloud/core_ext/string.rb, line 69 def camelize(lowercase_first_letter=nil) s = split('_').map { |w| w.capitalize }.join lowercase_first_letter ? s.uncapitalize : s end
# File lib/deltacloud/core_ext/string.rb, line 97 def convert_query_params(params={}) gsub(%r:(\w+)/) { |p| params.delete(p[1..-1].to_sym) } + params.to_query_params end
# File lib/deltacloud/core_ext/string.rb, line 41 def pluralize return self + 'es' if self =~ %ress$/ return self[0, self.length-1] + "ies" if self =~ %rty$/ return self if self =~ %rdata$/ self + "s" end
# File lib/deltacloud/core_ext/string.rb, line 93 def remove_matrix_params self.gsub(%r;([^\/]*)/, '').gsub(%r\?(.*)$/, '') end
# File lib/deltacloud/core_ext/string.rb, line 50 def singularize return self.gsub(%ries$/, 'y') if self =~ %ries$/ return self.gsub(%res$/, '') if self =~ %rsses$/ self.gsub(%rs$/, '') end
# File lib/deltacloud/core_ext/string.rb, line 35 def titlecase gsub(%r\b\w/){ $`[-1,1] == "'" ? $& : $&.upcase } end
# File lib/deltacloud/core_ext/string.rb, line 86 def truncate(length = 10) return self if self.length <= length end_string = "...#{self[(self.length-(length/2))..self.length]}" "#{self[0..(length/2)]}#{end_string}" end
# File lib/deltacloud/core_ext/string.rb, line 76 def uncapitalize self[0, 1].downcase + self[1..-1] end
# File lib/deltacloud/core_ext/string.rb, line 58 def underscore return self.downcase if self =~ %rVSPs$/ gsub(%r::/, '/'). gsub(%r([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(%r([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end
# File lib/deltacloud/core_ext/string.rb, line 81 def upcase_first self[0, 1].upcase + self[1..-1] end