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.1 lib/eco/data/strings/snake_case.rb
eco-helpers-3.0.0 lib/eco/data/strings/snake_case.rb
eco-helpers-2.7.25 lib/eco/data/strings/snake_case.rb
eco-helpers-2.7.24 lib/eco/data/strings/snake_case.rb
eco-helpers-2.7.23 lib/eco/data/strings/snake_case.rb
eco-helpers-2.7.22 lib/eco/data/strings/snake_case.rb
eco-helpers-2.7.21 lib/eco/data/strings/snake_case.rb
eco-helpers-2.7.20 lib/eco/data/strings/snake_case.rb
eco-helpers-2.7.19 lib/eco/data/strings/snake_case.rb
eco-helpers-2.7.18 lib/eco/data/strings/snake_case.rb
eco-helpers-2.7.17 lib/eco/data/strings/snake_case.rb
eco-helpers-2.7.16 lib/eco/data/strings/snake_case.rb
eco-helpers-2.7.15 lib/eco/data/strings/snake_case.rb
eco-helpers-2.7.14 lib/eco/data/strings/snake_case.rb
eco-helpers-2.7.13 lib/eco/data/strings/snake_case.rb
eco-helpers-2.7.12 lib/eco/data/strings/snake_case.rb
eco-helpers-2.7.4 lib/eco/data/strings/snake_case.rb
eco-helpers-2.7.2 lib/eco/data/strings/snake_case.rb
eco-helpers-2.7.1 lib/eco/data/strings/snake_case.rb
eco-helpers-2.7.0 lib/eco/data/strings/snake_case.rb