module Spectifly::Support
Public Instance Methods
camelize(string, lower = false)
click to toggle source
# File lib/spectifly/support.rb, line 5 def camelize(string, lower = false) string = if lower string.sub(/^[A-Z\d]*/) { $&.downcase } else string.sub(/^[a-z\d]*/) { $&.capitalize } end string = string.gsub(/(?:_| |(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::') end
get_module(constant)
click to toggle source
# File lib/spectifly/support.rb, line 26 def get_module(constant) tokens = constant.to_s.split('::') module_name = tokens[0, tokens.length - 1].join('::') module_name == '' ? nil : module_name end
lower_camelize(string)
click to toggle source
# File lib/spectifly/support.rb, line 14 def lower_camelize(string) camelize(string, true) end
tokenize(string)
click to toggle source
# File lib/spectifly/support.rb, line 18 def tokenize(string) return nil if string.nil? string = string.gsub(/&/, ' and '). gsub(/[ \/]+/, '_'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). downcase end