Sha256: f0c61c37f526eea5f6da48f554c406dd520790ce91707486bc137cf2b9fc4c8a

Contents?: true

Size: 831 Bytes

Versions: 3

Compression:

Stored size: 831 Bytes

Contents

module Natra
  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, Natra::Extensions::String)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
natra-0.0.3 lib/extensions/string.rb
natra-0.0.2 lib/extensions/string.rb
natra-0.0.1 lib/extensions/string.rb