Class: String

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

Overview

Flox-extensions to the standard Time class.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.random_uid(length = 16) ⇒ String

Returns creates a random alphanumeric string with a given length.

Returns:

  • (String)

    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_camelcaseString

Returns converts a string that separates its words with space, underscore or dash into its camelCase equivalent.

Returns:

  • (String)

    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_underscoreString

Returns converts a camelCase string to its under_score equivalent.

Returns:

  • (String)

    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