module AdwordsApi::Utils
Public Class Methods
format_id(id)
click to toggle source
Auxiliary method to format an ID to the pattern ###-###-####.
Args:
-
id: ID in unformatted form
Returns:
-
string containing the formatted ID
# 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)
click to toggle source
Returns the source operation index for an error.
Args:
-
error: the error to be analyzed
Returns:
-
index for the source operation, nil if none
# 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