Module: Stove::Util

Extended by:
Util
Included in:
Util
Defined in:
lib/stove/util.rb

Instance Method Summary collapse

Instance Method Details

#camelize(string) ⇒ String

Convert an underscored string to it’s camelcase equivalent constant.

Parameters:

  • the (String)

    string to convert

Returns:

  • (String)


48
49
50
51
52
53
54
# File 'lib/stove/util.rb', line 48

def camelize(string)
  string
    .to_s
    .split('_')
    .map { |e| e.capitalize }
    .join
end

#underscore(string) ⇒ String

Covert the given CaMelCaSeD string to under_score. Graciously borrowed from stackoverflow.com/questions/1509915.

Parameters:

  • string (String)

    the string to use for transformation

Returns:

  • (String)


30
31
32
33
34
35
36
37
38
# File 'lib/stove/util.rb', line 30

def underscore(string)
  string
    .to_s
    .gsub(/::/, '/')
    .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
    .gsub(/([a-z\d])([A-Z])/,'\1_\2')
    .tr('-', '_')
    .downcase
end

#version_for_url(version) ⇒ String

Convert a version string (x.y.z) to a community-site friendly format (x_y_z).

Examples:

Convert a version to a version string

format_version('1.2.3') #=> 1_2_3

Parameters:

  • version (#to_s)

    the version string to convert

Returns:

  • (String)


15
16
17
18
19
# File 'lib/stove/util.rb', line 15

def version_for_url(version)
  version
    .to_s
    .gsub('.', '_')
end