Class: Usps::Imis::Data
Overview
Convenience wrapper for accessing specific properties within an API data response
Instance Method Summary collapse
-
#[](property_name) ⇒ Object
Access an individual property value by name.
-
#entity ⇒ Object
The Business Object or Panel name.
-
#imis_id ⇒ Object
(also: #id)
Access the iMIS ID (i.e. Party ID) property.
-
#ordinal ⇒ Object
Access the Ordinal identifier property (if present).
-
#properties(include_ids: false) ⇒ Object
Hash of all property names to values.
-
#record_id ⇒ Object
Access the Record ID property.
Methods inherited from BaseData
#[]=, from_json, #inspect, #pretty_print
Instance Method Details
#[](property_name) ⇒ Object
Access an individual property value by name
32 33 34 35 36 37 38 |
# File 'lib/usps/imis/data.rb', line 32 def [](property_name) property = property_values.find { it['Name'] == property_name } return if property.nil? value = property['Value'] value.nil? || value.is_a?(String) ? value : value['$value'] end |
#entity ⇒ Object
The Business Object or Panel name
15 |
# File 'lib/usps/imis/data.rb', line 15 def entity = raw['EntityTypeName'] |
#imis_id ⇒ Object Also known as: id
Access the iMIS ID (i.e. Party ID) property
19 |
# File 'lib/usps/imis/data.rb', line 19 def imis_id = raw['PrimaryParentIdentity']['IdentityElements']['$values'].first.to_i |
#ordinal ⇒ Object
Access the Ordinal identifier property (if present)
28 |
# File 'lib/usps/imis/data.rb', line 28 def ordinal = self['Ordinal']&.to_i |
#properties(include_ids: false) ⇒ Object
Hash of all property names to values
44 45 46 47 48 49 |
# File 'lib/usps/imis/data.rb', line 44 def properties(include_ids: false) property_values .map { it['Name'] } .select { include_ids || !%w[ID Ordinal].include?(it) } .index_with { self[it] } end |
#record_id ⇒ Object
Access the Record ID property
24 |
# File 'lib/usps/imis/data.rb', line 24 def record_id = raw['Identity']['IdentityElements']['$values'].first.to_i |