Module: AdwordsApi::Utils

Defined in:
lib/adwords_api/utils.rb

Class Method Summary collapse

Class Method Details

.format_id(id) ⇒ Object

Auxiliary method to format an ID to the pattern ###-###-####.

Args:

  • id: ID in unformatted form

Returns:

  • string containing the formatted ID



47
48
49
50
51
52
53
54
# File 'lib/adwords_api/utils.rb', line 47

def self.format_id(id)
  str_id = id.to_s.gsub(/\D/, '')
  if str_id.size >= 7
    str_array = str_id.scan(/(\d{3})(\d{3})(\d+)/)
    str_id = str_array.join('-') unless str_array.empty?
  end
  return str_id
end

.operation_index_for_error(error) ⇒ Object

Returns the source operation index for an error.

Args:

  • error: the error to be analyzed

Returns:

  • index for the source operation, nil if none



31
32
33
34
35
36
37
# File 'lib/adwords_api/utils.rb', line 31

def self.operation_index_for_error(error)
  if error and error[:field_path] and error[:field_path].kind_of?(String)
    match = error[:field_path].match(/operations\[(\d+)\]/)
    return match ? match[1].to_i : nil
  end
  return nil
end