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 property.
-
#ordinal ⇒ Object
Access the Ordinal identifier property (if present).
-
#properties(include_ids: false) ⇒ Object
Hash of all property names to values.
Methods inherited from BaseData
#[]=, from_json, #inspect, #pretty_print
Instance Method Details
#[](property_name) ⇒ Object
Access an individual property value by name
28 29 30 31 32 33 34 |
# File 'lib/usps/imis/data.rb', line 28 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 property
19 |
# File 'lib/usps/imis/data.rb', line 19 def imis_id = self['ID'].to_i |
#ordinal ⇒ Object
Access the Ordinal identifier property (if present)
24 |
# File 'lib/usps/imis/data.rb', line 24 def ordinal = self['Ordinal']&.to_i |
#properties(include_ids: false) ⇒ Object
Hash of all property names to values
40 41 42 43 44 45 |
# File 'lib/usps/imis/data.rb', line 40 def properties(include_ids: false) property_values .map { it['Name'] } .select { include_ids || !%w[ID Ordinal].include?(it) } .index_with { self[it] } end |