Sha256: 350baebcc44f16c22fd58537917d4f2036a4babe3bcc3c7d574f88e9e8b34512
Contents?: true
Size: 1.71 KB
Versions: 8
Compression:
Stored size: 1.71 KB
Contents
module ZendeskAPI # @private module Helpers def self.present?(value) ![nil, false, "", " ", [], {}].include?(value) end # From https://github.com/rubyworks/facets/blob/master/lib/core/facets/string/modulize.rb # Converts a string to module name representation. # # This is essentially #camelcase, but it also converts # '/' to '::' which is useful for converting paths to # namespaces. # # Examples # # "method_name".modulize #=> "MethodName" # "method/name".modulize #=> "Method::Name" # # @param string [string] input, `module/class_name` # @return [string] a string that can become a class, `Module::ClassName` def self.modulize_string(string) # gsub('__','/'). # why was this ever here? string.gsub(/__(.?)/) { "::#{$1.upcase}" }. gsub(/\/(.?)/) { "::#{$1.upcase}" }. gsub(/(?:_+|-+)([a-z])/) { $1.upcase }. gsub(/(\A|\s)([a-z])/) { $1 + $2.upcase } end # From https://github.com/rubyworks/facets/blob/master/lib/core/facets/string/snakecase.rb # Underscore a string such that camelcase, dashes and spaces are # replaced by underscores. This is the reverse of {#camelcase}, # albeit not an exact inverse. # # "SnakeCase".snakecase #=> "snake_case" # "Snake-Case".snakecase #=> "snake_case" # "Snake Case".snakecase #=> "snake_case" # "Snake - Case".snakecase #=> "snake_case" def self.snakecase_string(string) # gsub(/::/, '/'). string.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'). gsub(/([a-z\d])([A-Z])/, '\1_\2'). tr('-', '_'). gsub(/\s/, '_'). gsub(/__+/, '_'). downcase end end end
Version data entries
8 entries across 8 versions & 1 rubygems