Module: AdwordsApi::Utils
- Defined in:
- lib/adwords_api/utils.rb
Class Method Summary collapse
-
.format_id(id) ⇒ Object
Auxiliary method to format an ID to the pattern ###-###-####.
-
.map(entries) ⇒ Object
Gets a map from an array of map entries.
-
.operation_index_for_error(error) ⇒ Object
Returns the source operation index for an error.
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
71 72 73 74 75 76 77 78 |
# File 'lib/adwords_api/utils.rb', line 71 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 |
.map(entries) ⇒ Object
Gets a map from an array of map entries. A map entry is any object that has a key and value field.
Args:
-
entries: list of map entries
Returns:
-
hash constructed from map entries
36 37 38 39 40 41 42 |
# File 'lib/adwords_api/utils.rb', line 36 def self.map(entries) map = {} entries.each do |entry| map[entry[:key]] = entry[:value] end return map 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
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/adwords_api/utils.rb', line 52 def self.operation_index_for_error(error) if error and error[:field_path] parts = error[:field_path].split('.') if parts.length > 0 match = parts.first.match(/operations\[(\d)\]/) return match ? match[1].to_i : nil end end return nil end |