module Artifactory::Util

def camelize(string, lowercase = false)

Returns:
  • (String) -

Parameters:
  • string (String) --
def camelize(string, lowercase = false)
  result = string
    .to_s
    .split('_')
    .map { |e| e.capitalize }
    .join
  if lowercase
    result[0,1].downcase + result[1..-1]
  else
    result
  end
end

def numeric?(string)

def numeric?(string)
  string.to_i.to_s == string || string.to_f.to_s == string
end

def rename_keys(options, map = {})

Returns:
  • (Hash) -

Parameters:
  • map (Hash) --
  • options (Hash) --

Other tags:
    Example: Rename the given keys -
def rename_keys(options, map = {})
  Hash[options.map { |k, v| [map[k] || k, v] }]
end

def slice(options, *keys)

Returns:
  • (Hash) -

Parameters:
  • keys (Array) --
  • options (Hash) --
  • def slice(options, *keys)
      keys.inject({}) do |hash, key|
        hash[key] = options[key] if options[key]
        hash
      end
    end

    def to_type(string)

    def to_type(string)
      return true if string.eql?('true')
      return false if string.eql?('false')
      return string.to_i if numeric?(string)
      return string
    end

    def truncate(string, options = {})

    Parameters:
    • options (Hash) --
    • string (String) --
    def truncate(string, options = {})
      length = options[:length] || 30
      if string.length > length
        string[0..length-3] + '...'
      else
        string
      end
    end

    def underscore(string)

    Returns:
    • (String) -

    Parameters:
    • string (String) --
    def underscore(string)
      string
        .to_s
        .gsub(/::/, '/')
        .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
        .gsub(/([a-z\d])([A-Z])/,'\1_\2')
        .tr('-', '_')
        .downcase
    end

    def xml_to_hash(element, child_with_children = '', unique_children = true)

    Parameters:
    • element (REXML) --
    def xml_to_hash(element, child_with_children = '', unique_children = true)
      properties = {}
      element.each_element_with_text do |e|
        if e.name.eql?(child_with_children)
          if unique_children
            e.each_element_with_text do |t|
              properties[t.name] = to_type(t.text)
            end
          else
            children = []
            e.each_element_with_text do |t|
              properties[t.name] = children.push(to_type(t.text))
            end
          end
        else
          properties[e.name] = to_type(e.text)
        end
      end
      properties
    end