Class: Attio::Util::IdExtractor
- Inherits:
-
Object
- Object
- Attio::Util::IdExtractor
- Defined in:
- lib/attio/util/id_extractor.rb
Overview
Centralized ID extraction utility for handling various ID formats across different Attio resources
Class Method Summary collapse
-
.extract(id, key = nil) ⇒ String?
Extract an ID from various formats.
-
.extract_for_resource(id, resource_type) ⇒ String?
Extract a specific ID type from a potentially nested structure.
-
.normalize(id, resource_type) ⇒ Hash, ...
Normalize an ID structure to a consistent format.
Class Method Details
.extract(id, key = nil) ⇒ String?
Extract an ID from various formats
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/attio/util/id_extractor.rb', line 13 def extract(id, key = nil) return nil if id.nil? case id when String id when Hash extract_from_hash(id, key) else id.to_s if id.respond_to?(:to_s) end end |
.extract_for_resource(id, resource_type) ⇒ String?
Extract a specific ID type from a potentially nested structure
30 31 32 33 34 35 36 37 |
# File 'lib/attio/util/id_extractor.rb', line 30 def extract_for_resource(id, resource_type) return nil if id.nil? key = resource_key_map[resource_type] return id if id.is_a?(String) && key.nil? extract(id, key) end |
.normalize(id, resource_type) ⇒ Hash, ...
Normalize an ID structure to a consistent format
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/attio/util/id_extractor.rb', line 43 def normalize(id, resource_type) return nil if id.nil? extracted = extract_for_resource(id, resource_type) return nil if extracted.nil? # For resources that need hash format if hash_format_resources.include?(resource_type) key = resource_key_map[resource_type] key ? {key => extracted} : extracted else extracted end end |