Sha256: 946f48e336026a467b6e05d22d775723259ff63532b983843a6c6efaec836766

Contents?: true

Size: 464 Bytes

Versions: 5

Compression:

Stored size: 464 Bytes

Contents

module Shirinji
  module Utils
    module String
      CAMEL =
        /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/

      module_function

      def camelcase(str)
        chunks = str.to_s.split('_').map do |w|
          w = w.downcase
          w[0] = w[0].upcase
          w
        end

        chunks.join
      end

      def snakecase(str)
        str.gsub(CAMEL) { |s| s.split('').join('_') }.downcase
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
shirinji-0.0.8 lib/shirinji/utils/string.rb
shirinji-0.0.7 lib/shirinji/utils/string.rb
shirinji-0.0.6 lib/shirinji/utils/string.rb
shirinji-0.0.5 lib/shirinji/utils/string.rb
shirinji-0.0.4 lib/shirinji/utils/string.rb