Module: Stove::Util
Instance Method Summary collapse
-
#camelize(string) ⇒ String
Convert an underscored string to it’s camelcase equivalent constant.
-
#underscore(string) ⇒ String
Covert the given CaMelCaSeD string to under_score.
-
#version_for_url(version) ⇒ String
Convert a version string (x.y.z) to a community-site friendly format (x_y_z).
Instance Method Details
#camelize(string) ⇒ String
Convert an underscored string to it’s camelcase equivalent constant.
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.
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).
15 16 17 18 19 |
# File 'lib/stove/util.rb', line 15 def version_for_url(version) version .to_s .gsub('.', '_') end |