Sha256: ba1444d028be2b7a7c104a89cee17b91bc893935fdceef3a6ad779753d24359e

Contents?: true

Size: 900 Bytes

Versions: 10

Compression:

Stored size: 900 Bytes

Contents

module DebitechSoap
  module StringExtensions

    module Underscore
      def underscore
        word = dup
        word.gsub!(/::/, '/')
        word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
        word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
        word.tr!("-", "_")
        word.downcase!
        word
      end
    end

    module CamelCase
      def camelcase(first_letter_in_uppercase = true)
        if first_letter_in_uppercase
          self.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
        else
          self.to_s[0].chr.downcase + self.camelcase[1..-1]
        end
      end
    end

  end
end

unless String.methods.include?('underscore')
  String.class_eval do
    include DebitechSoap::StringExtensions::Underscore
  end
end

unless String.methods.include?('camelcase')
  String.class_eval do
    include DebitechSoap::StringExtensions::CamelCase
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
debitech_soap-1.2.0 lib/debitech_soap/string_extensions.rb
debitech_soap-1.1.0 lib/debitech_soap/string_extensions.rb
debitech_soap-1.0.3 lib/debitech_soap/string_extensions.rb
debitech_soap-1.0.2 lib/debitech_soap/string_extensions.rb
debitech_soap-1.0.1 lib/debitech_soap/string_extensions.rb
debitech_soap-1.0.0 lib/debitech_soap/string_extensions.rb
debitech_soap-0.0.6 lib/debitech_soap/string_extensions.rb
debitech_soap-0.0.5 lib/debitech_soap/string_extensions.rb
debitech_soap-0.0.4 lib/debitech_soap/string_extensions.rb
debitech_soap-0.0.3 lib/debitech_soap/string_extensions.rb