Sha256: e0579de179158fdbf468a3ed53b96f4b2cd769535fe70ef943c989049ca986f5

Contents?: true

Size: 638 Bytes

Versions: 2

Compression:

Stored size: 638 Bytes

Contents

# frozen_string_literal: true

module BingAdsRubySdk
  module StringUtils
    def self.camelize(string)
      string.split(UNDERSCORE).collect! { |w| w.capitalize }.join
    end

    def self.snakize(string)
      raise "Unexpected string length : #{string.length} for string '#{string[0..200]}...'" if string.length > 1000

      string.gsub(MULTIPLE_CAPSREGEX, MATCHING_PATTERN)
        .gsub(SPLIT_REGEX, MATCHING_PATTERN)
        .tr("-", "_")
        .downcase
        .to_sym
    end

    UNDERSCORE = "_"
    MULTIPLE_CAPSREGEX = /([A-Z]+)([A-Z][a-z])/
    SPLIT_REGEX = /([a-z\d])([A-Z])/
    MATCHING_PATTERN = '\1_\2'
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bing_ads_ruby_sdk-1.7 lib/bing_ads_ruby_sdk/string_utils.rb
bing_ads_ruby_sdk-1.6 lib/bing_ads_ruby_sdk/string_utils.rb