Class: String
Overview
– Copyright © 2013 RightScale, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ++
Instance Method Summary collapse
-
#_arrayify ⇒ Array
Wraps the string into an array.
-
#_blank? ⇒ Boolean
Returns
trueis the string has zero length or contains spaces only. -
#_camelize(lower_case = false) ⇒ String
(also: #_camel_case)
Camelizes the string.
-
#_constantize ⇒ Class, Module
Constantizes the string.
-
#_snake_case ⇒ String
(also: #_underscore)
Underscorizes the string.
Instance Method Details
#_arrayify ⇒ Array
Wraps the string into an array.
85 86 87 |
# File 'lib/base/helpers/support.rb', line 85 def _arrayify [ self ] end |
#_blank? ⇒ Boolean
Returns true is the string has zero length or contains spaces only. And it returns false if the string has any meaningful value.
94 95 96 |
# File 'lib/base/helpers/support.rb', line 94 def _blank? empty? || strip.empty? end |
#_camelize(lower_case = false) ⇒ String Also known as: _camel_case
Camelizes the string.
54 55 56 57 58 59 60 61 |
# File 'lib/base/helpers/support.rb', line 54 def _camelize(lower_case = false) words = self.gsub(/([A-Z])/, '_\1'). split(/_|\b/). map{ |word| word.capitalize }. reject{ |word| word == '' } words[0] = words[0].downcase if words[0] && lower_case words.join('') end |
#_constantize ⇒ Class, Module
Constantizes the string.
36 37 38 39 40 41 |
# File 'lib/base/helpers/support.rb', line 36 def _constantize unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ self fail(::NameError, "#{self.inspect} is not a valid constant name!") end Object.module_eval("::#{$1}", __FILE__, __LINE__) end |
#_snake_case ⇒ String Also known as: _underscore
Underscorizes the string.
71 72 73 74 75 |
# File 'lib/base/helpers/support.rb', line 71 def _snake_case self.split(/\b/). map{ |word| word.gsub(/[A-Z]/){ |match| "#{$`=='' ? '' : '_'}#{match.downcase}" } }. join('') end |