Sha256: 63a70c526a25fff96a6c863d02396caac73dc8be90dc4527986e106357036a7a
Contents?: true
Size: 1.18 KB
Versions: 40
Compression:
Stored size: 1.18 KB
Contents
module Eco module Data module Strings module CamelCase # From ActiveSupport # @see https://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-camelize def camel_case(term, uppercase_first_letter = false) string = term.to_s # String#camelize takes a symbol (:upper or :lower), so here we also support :lower to keep the methods consistent. if !uppercase_first_letter || uppercase_first_letter == :lower string = string.sub(camel_regex) { |match| match.downcase! || match } elsif string.match?(/\A[a-z\d]*\z/) return string.capitalize else string = string.sub(/^[a-z\d]*/) { |match| match.capitalize! || match } end string.gsub!(/(?:_|(\/))([a-z\d]*)/i) do word = $2 substituted = word.capitalize! || word $1 ? "::#{substituted}" : substituted end string end def camel_regex @camel_regex ||= /^(?:#{acro_regex}(?=\b|[A-Z_])|\w)/ end def acro_regex @acro_regex ||= /(?=a)b/ end end end end end
Version data entries
40 entries across 40 versions & 1 rubygems