Sha256: 69f94c2487e2af52dee960ea89d6dbd4b760df217529767d8738be7fee8042a8

Contents?: true

Size: 835 Bytes

Versions: 14

Compression:

Stored size: 835 Bytes

Contents

module Corneal
  module Extensions
    module String
      def camel_case
        return self.gsub(/^./) { |l| l.capitalize } if !match(/[_-]/)
        altered_self = self.downcase.capitalize
        altered_self.scan(/[_-][a-zA-Z]/).each do |match|
          altered_self.gsub!(match, match[1].upcase)
        end

        altered_self
      end

      def camel_case!
        self.replace camel_case
      end

      def directory_name
        self.downcase.gsub(/[^a-z|\-|\_]/, '')
      end

      def file_name
        self.gsub(/[\-| ]/, '_').
             gsub(/([A-Z]+|[A-Z][a-z])/) { |x| "_#{x}" }.
             sub(/^_/, "").
             gsub(/_{2,}+/, "_").
             downcase
      end

      def file_name!
        self.replace file_name
      end
    end
  end
end

String.send(:include, Corneal::Extensions::String)

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
corneal-new-1.3.1 lib/extensions/string.rb
corneal-new-1.3.0 lib/extensions/string.rb
corneal-1.2.3 lib/extensions/string.rb
corneal-1.2.2 lib/extensions/string.rb
corneal-1.2.1 lib/extensions/string.rb
corneal-1.2.0 lib/extensions/string.rb
corneal-1.1.0 lib/extensions/string.rb
corneal-1.0.0 lib/extensions/string.rb
corneal-0.1.5 lib/extensions/string.rb
corneal-0.1.4 lib/extensions/string.rb
corneal-0.1.3 lib/extensions/string.rb
corneal-0.1.2 lib/extensions/string.rb
corneal-0.1.1 lib/extensions/string.rb
corneal-0.1.0 lib/extensions/string.rb