Sha256: 513d15546718b384cbc0b83f7be76dc20f9eb530e29b7ccb653ff980e5d8fd19

Contents?: true

Size: 582 Bytes

Versions: 40

Compression:

Stored size: 582 Bytes

Contents

module Eco
  module Data
    module Strings
      module SnakeCase
        # From ActiveSupport
        # @see https://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-underscore
        def snake_case(camel_cased_word)
          return camel_cased_word.to_s.dup unless /[A-Z-]|::/.match?(camel_cased_word)
          word = camel_cased_word.to_s.gsub("::", "/")
          word.gsub!(/(?<=[A-Z])(?=[A-Z][a-z])|(?<=[a-z\d])(?=[A-Z])/, "_")
          word.tr!("-", "_")
          word.downcase!
          word
        end
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
eco-helpers-3.0.21 lib/eco/data/strings/snake_case.rb
eco-helpers-3.0.20 lib/eco/data/strings/snake_case.rb
eco-helpers-3.0.19 lib/eco/data/strings/snake_case.rb
eco-helpers-3.0.18 lib/eco/data/strings/snake_case.rb
eco-helpers-3.0.17 lib/eco/data/strings/snake_case.rb
eco-helpers-3.0.16 lib/eco/data/strings/snake_case.rb
eco-helpers-3.0.15 lib/eco/data/strings/snake_case.rb
eco-helpers-3.0.14 lib/eco/data/strings/snake_case.rb
eco-helpers-3.0.13 lib/eco/data/strings/snake_case.rb
eco-helpers-3.0.12 lib/eco/data/strings/snake_case.rb
eco-helpers-3.0.11 lib/eco/data/strings/snake_case.rb
eco-helpers-3.0.10 lib/eco/data/strings/snake_case.rb
eco-helpers-3.0.9 lib/eco/data/strings/snake_case.rb
eco-helpers-3.0.8 lib/eco/data/strings/snake_case.rb
eco-helpers-3.0.7 lib/eco/data/strings/snake_case.rb
eco-helpers-3.0.6 lib/eco/data/strings/snake_case.rb
eco-helpers-3.0.5 lib/eco/data/strings/snake_case.rb
eco-helpers-3.0.4 lib/eco/data/strings/snake_case.rb
eco-helpers-3.0.3 lib/eco/data/strings/snake_case.rb
eco-helpers-3.0.2 lib/eco/data/strings/snake_case.rb