Sha256: a2d1728db33572dc77f4eccf4691a254cf2f5a8321ad4b24f065d2a0ca3b863a

Contents?: true

Size: 1.06 KB

Versions: 55

Compression:

Stored size: 1.06 KB

Contents

module PactBroker
  module StringRefinements
    refine String do
      def not_blank?
        !blank?
      end

      def blank?
        self.strip.size == 0
      end

      # ripped from rubyworks/facets, thank you
      def snakecase
        gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
        .gsub(/([a-z\d])([A-Z])/,'\1_\2')
        .tr('-', '_')
        .gsub(/\s/, '_')
        .gsub(/__+/, '_')
        .downcase
      end

      # ripped from rubyworks/facets, thank you
      def camelcase(*separators)
        case separators.first
        when Symbol, TrueClass, FalseClass, NilClass
          first_letter = separators.shift
        end

        separators = ['_', '\s'] if separators.empty?

        str = self.dup

        separators.each do |s|
          str = str.gsub(/(?:#{s}+)([a-z])/){ $1.upcase }
        end

        case first_letter
        when :upper, true
          str = str.gsub(/(\A|\s)([a-z])/){ $1 + $2.upcase }
        when :lower, false
          str = str.gsub(/(\A|\s)([A-Z])/){ $1 + $2.downcase }
        end

        str
      end
    end
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
pact_broker-2.79.1 lib/pact_broker/string_refinements.rb
pact_broker-2.79.0 lib/pact_broker/string_refinements.rb
pact_broker-2.78.1 lib/pact_broker/string_refinements.rb
pact_broker-2.78.0 lib/pact_broker/string_refinements.rb
pact_broker-2.77.0 lib/pact_broker/string_refinements.rb
pact_broker-2.76.2 lib/pact_broker/string_refinements.rb
pact_broker-2.76.1 lib/pact_broker/string_refinements.rb
pact_broker-2.76.0 lib/pact_broker/string_refinements.rb
pact_broker-2.75.0 lib/pact_broker/string_refinements.rb
pact_broker-2.74.1 lib/pact_broker/string_refinements.rb
pact_broker-2.74.0 lib/pact_broker/string_refinements.rb
pact_broker-2.73.0 lib/pact_broker/string_refinements.rb
pact_broker-2.72.0 lib/pact_broker/string_refinements.rb
pact_broker-2.71.0 lib/pact_broker/string_refinements.rb
pact_broker-2.70.0 lib/pact_broker/string_refinements.rb
pact_broker-2.69.0 lib/pact_broker/string_refinements.rb
pact_broker-2.68.1 lib/pact_broker/string_refinements.rb
pact_broker-2.68.0 lib/pact_broker/string_refinements.rb
pact_broker-2.67.0 lib/pact_broker/string_refinements.rb
pact_broker-2.66.0 lib/pact_broker/string_refinements.rb