Sha256: 9475b543af54cc7941f8900459202f27f9d809cb0bb029359576df7d80dd468a

Contents?: true

Size: 495 Bytes

Versions: 6

Compression:

Stored size: 495 Bytes

Contents

module Buff
  module Extensions::String
    module Inflections
      def underscore
        word = self.dup
        word.gsub!('::', '/')
        word.gsub!(/(?:([A-Za-z\d])|^)((?=a)b)(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}#{$2.downcase}" }
        word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
        word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
        word.tr!("-", "_")
        word.downcase!
        word
      end
    end
  end
end

class String
  include Buff::Extensions::String::Inflections
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
buff-extensions-2.0.0 lib/buff/extensions/string/inflections.rb
buff-extensions-1.0.0 lib/buff/extensions/string/inflections.rb
buff-extensions-0.5.0 lib/buff/extensions/string/inflections.rb
buff-extensions-0.4.0 lib/buff/extensions/string/inflections.rb
buff-extensions-0.3.1 lib/buff/extensions/string/inflections.rb
buff-extensions-0.3.0 lib/buff/extensions/string/inflections.rb