Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/flox/utils.rb
Overview
Flox-extensions to the standard Time class.
Class Method Summary collapse
-
.random_uid(length = 16) ⇒ String
Creates a random alphanumeric string with a given length.
Instance Method Summary collapse
-
#to_camelcase ⇒ String
Converts a string that separates its words with space, underscore or dash into its
camelCase
equivalent. -
#to_underscore ⇒ String
Converts a
camelCase
string to itsunder_score
equivalent.
Class Method Details
.random_uid(length = 16) ⇒ String
Returns creates a random alphanumeric string with a given length.
22 23 24 |
# File 'lib/flox/utils.rb', line 22 def self.random_uid(length=16) SecureRandom.base64(length * 2).gsub(/[\+\/]/, '').slice(0, length) end |
Instance Method Details
#to_camelcase ⇒ String
Returns converts a string that separates its words with space,
underscore or dash into its camelCase
equivalent.
33 34 35 36 |
# File 'lib/flox/utils.rb', line 33 def to_camelcase words = downcase.split(/[_\-\s]/) words.shift + words.map(&:capitalize).join end |
#to_underscore ⇒ String
Returns converts a camelCase
string to its under_score
equivalent.
27 28 29 |
# File 'lib/flox/utils.rb', line 27 def to_underscore gsub(/(.)([A-Z])/,'\1_\2').downcase end |