# module Chef::Mixin::ConvertToClassName

### Public Instance Methods

convert_to_class_name(str) click to toggle source

    # File lib/chef/mixin/convert_to_class_name.rb, line 25
    def convert_to_class_name(str)
      str = str.dup
      str.gsub!(/[^A-Za-z0-9_]/,'_')
      rname = nil
      regexp = %r{^(.+?)(_(.+))?$}

      mn = str.match(regexp)
      if mn
        rname = mn[1].capitalize

        while mn && mn[3]
          mn = mn[3].match(regexp)
          rname << mn[1].capitalize if mn
        end
      end

      rname
    end

convert_to_snake_case(str, namespace=nil) click to toggle source

    # File lib/chef/mixin/convert_to_class_name.rb, line 44
    def convert_to_snake_case(str, namespace=nil)
      str = str.dup
      str.sub!(/^#{namespace}(\:\:)?/, '') if namespace
      str.gsub!(/[A-Z]/) {|s| "_" + s}
      str.downcase!
      str.sub!(/^\_/, "")
      str
    end

filename_to_qualified_string(base, filename) click to toggle source

    # File lib/chef/mixin/convert_to_class_name.rb, line 58
    def filename_to_qualified_string(base, filename)
      file_base = File.basename(filename, ".rb")
      base.to_s + (file_base == 'default' ? '' : "_#{file_base}")
    end

snake_case_basename(str) click to toggle source

    # File lib/chef/mixin/convert_to_class_name.rb, line 53
    def snake_case_basename(str)
      with_namespace = convert_to_snake_case(str)
      with_namespace.split("::").last.sub(/^_/, '')
    end