Recursively converts CamelCase and camelBack JSON-style hash keys to
 Rubyish snake_case, suitable for use during instantiation of Ruby
 model attributes.
358469
def to_snake_keys(value = self)
      case value
      when Array
        value.map { |v| to_snake_keys(v) }
      when Hash
        snake_hash(value)
      else
        value
      end
    end
906824
def snake2ucamel(value):
    """"""
    UNDER, LETTER, OTHER = object(), object(), object()
    def group_key_function(char):
        if char == "_":
            return UNDER
        if char in string.ascii_letters:
            return LETTER
        return OTHER
    def process_group(idx, key, chars):
        if key is LETTER:
            return "".join([chars[0].upper()] + chars[1:])
        if key is OTHER     \
        or len(chars) != 1  \
        or idx in [0, last] \
        or LETTER not in (groups[idx-1][1], groups[idx+1][1]):
            return "".join(chars)
        return ""
    raw_groups_gen = itertools.groupby(value, key=group_key_function)
    groups = [(idx, key, list(group_gen))
              for idx, (key, group_gen) in enumerate(raw_groups_gen)]
    last = len(groups) - 1
    return "".join(itertools.starmap(process_group, groups))
458200
function snakeCase(str) {
            return camelCase(str).replace(reCamelCase, function (all, letter) {
                return "-" + letter.toLowerCase();
            });
        }
1170299
def to_h
      Hash[
        attribute_names.
        map do |name| [
          name.to_s.gsub("@","").to_sym,  # key
          (instance_variable_get(name) rescue send(name))] # val
        end
      ]
    end
973023
def snake_case_to_camel_case(value)
      pieces = value.to_s.split '_'

      (pieces.first + pieces[1..-1].map(&:capitalize).join).to_sym
    end
108580
def json_repr(self, minimal=False):
        
        if minimal:
            return {to_camel_case(k): v for k, v in vars(self).items() if (v or v is False or v == 0)}
        else:
            return {to_camel_case(k): v for k, v in vars(self).items()}
44988
function camelCase(str, { upperCase = false } = {}) {
  if (str.length === 0) {
    return str;
  }

  if (upperCase && isAllUpperCaseSnakeCase(str)) {
    // Only convert to lower case if the string is all upper
    // case snake_case. This allowes camelCase strings to go
    // through without changing.
    str = str.toLowerCase();
  }

  let out = str[0];

  for (let i = 1, l = str.length; i < l; ++i) {
    const char = str[i];
    const prevChar = str[i - 1];

    if (char !== '_') {
      if (prevChar === '_') {
        out += char.toUpperCase();
      } else {
        out += char;
      }
    }
  }

  return out;
}
528652
def convert_hash_keys(value)
        case value
        when Array
          value.map { |v| convert_hash_keys(v) }
        when Hash
          Hash[value.map { |k, v| [k.to_snake_case.to_sym, convert_hash_keys(v)] }]
        else
          value
        end
      end
668640
def kebab_case(string):
    
    if not string:
        return string
    string = string.replace('_', '-').replace(' ', '-')
    return de_camel(string, '-')
526514
def to_hash(options = {})
      out = {}
      each_key do |k|
        assignment_key =
          if options[:stringify_keys]
            k.to_s
          elsif options[:symbolize_keys]
            k.to_s.to_sym
          else
            k
          end
        if self[k].is_a?(Array)
          out[assignment_key] ||= []
          self[k].each do |array_object|
            out[assignment_key] << maybe_convert_to_hash(array_object, options)
          end
        else
          out[assignment_key] = maybe_convert_to_hash(self[k], options)
        end
      end
      out
    end
775782
def snake_case_to_headless_camel_case(snake_string):
  
  return ''.join([snake_string.split('_')[0]] +
                 list(sub_string.capitalize()
                      for sub_string in snake_string.split('_')[1:]))
941103
def to_snake_case(s):
    """"""
    return re.sub('([^_A-Z])([A-Z])', lambda m: m.group(1) + '_' + m.group(2).lower(), s)
638109
def camel_to_snake_case(string):
    
    s = _1.sub(r'\1_\2', string)
    return _2.sub(r'\1_\2', s).lower()
93184
def camel_to_snake(camel):
    """"""
    ret = []
    last_lower = False
    for char in camel:
        current_upper = char.upper() == char
        if current_upper and last_lower:
            ret.append("_")
            ret.append(char.lower())
        else:
            ret.append(char.lower())
        last_lower = not current_upper
    return "".join(ret)
1233898
def to_hash(args = {}) # :nodoc:
      args ||= {}
      hash = {}

      self.attributes.each do |name, value|
        hash[name] = if value.is_a?(::Array)
          value.map {|x| x.respond_to?(:to_hash) ? call_method_with_optional_parameters(x, :to_hash, :nested => true) : x}
        elsif value.respond_to?(:to_hash)
          call_method_with_optional_parameters(value, :to_hash, :nested => true)
        elsif value.respond_to?(:as_json)
          value.as_json(:nested => true)
        else
          value
        end
      end

      hash
    end
931919
function snakeCase (str) {
  return str
    .replace(/([a-z])([A-Z])/g, match => match[0] + '_' + match[1])
    .replace(invalidChars, '_')
    .toLowerCase()
}
1135188
def to_dot_attributes(hash)
      # TODO: fix uncompatible key names
      # TODO: some values must be encoded (backquoting and the like)
      buffer = ""
      hash.each_pair do |k,v|
        buffer << " " unless buffer.empty?
        v = case v
          when Array
            if v.all?{|elm| Array===elm and elm.length==2 and elm.all?{|subelm| Numeric===subelm}}
              v.inject('') {|memo, elm| "#{memo} #{elm.join(',')}"}.strip
            else
              v.join(', ')
            end
          else
            v.to_s
        end
        buffer << "#{k}=\"#{v}\""
      end
      buffer
    end