Sha256: f455e69c6daaa35e12b1a4298a7d60cfb3868a4c1d2a90e857f5d80124621b07

Contents?: true

Size: 800 Bytes

Versions: 11

Compression:

Stored size: 800 Bytes

Contents

module Spectifly
  module Support
    module_function

    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

    def lower_camelize(string)
      camelize(string, true)
    end

    def tokenize(string)
      return nil if string.nil?
      string = string.gsub(/&/, ' and ').
        gsub(/[ \/]+/, '_').
        gsub(/([a-z\d])([A-Z])/,'\1_\2').
        downcase
    end

    def get_module(constant)
      tokens = constant.to_s.split('::')
      module_name = tokens[0, tokens.length - 1].join('::')
      module_name == '' ? nil : module_name
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
spectifly-0.0.11 lib/spectifly/support.rb
spectifly-0.0.10 lib/spectifly/support.rb
spectifly-0.0.9 lib/spectifly/support.rb
spectifly-0.0.8 lib/spectifly/support.rb
spectifly-0.0.7 lib/spectifly/support.rb
spectifly-0.0.6 lib/spectifly/support.rb
spectifly-0.0.5 lib/spectifly/support.rb
spectifly-0.0.4 lib/spectifly/support.rb
spectifly-0.0.3 lib/spectifly/support.rb
spectifly-0.0.2 lib/spectifly/support.rb
spectifly-0.0.1 lib/spectifly/support.rb