Class: Usps::Imis::Data
- Inherits:
-
Hash
- Object
- Hash
- Usps::Imis::Data
- Defined in:
- lib/usps/imis/data.rb
Overview
Convenience wrapper for accessing specific properties within an API data response
Class Method Summary collapse
-
.from_json(json) ⇒ Object
Load raw API response JSON to access properties.
Instance Method Summary collapse
-
#[](property_name) ⇒ Object
Access an individual property value by name.
-
#imis_id ⇒ Object
(also: #id)
Access the iMIS ID property.
- #inspect ⇒ Object
-
#ordinal ⇒ Object
Access the Ordinal identifier property (if present).
- #pretty_print(pp) ⇒ Object
Class Method Details
.from_json(json) ⇒ Object
Load raw API response JSON to access properties
15 |
# File 'lib/usps/imis/data.rb', line 15 def self.from_json(json) = self[JSON.parse(json)] |
Instance Method Details
#[](property_name) ⇒ Object
Access an individual property value by name
30 31 32 33 34 35 36 |
# File 'lib/usps/imis/data.rb', line 30 def [](property_name) property = raw['Properties']['$values'].find { it['Name'] == property_name } return if property.nil? value = property['Value'] value.is_a?(String) ? value : value['$value'] end |
#imis_id ⇒ Object Also known as: id
Access the iMIS ID property
21 |
# File 'lib/usps/imis/data.rb', line 21 def imis_id = self['ID'] |
#inspect ⇒ Object
38 39 40 41 42 |
# File 'lib/usps/imis/data.rb', line 38 def inspect stringio = StringIO.new PP.pp(self, stringio) stringio.string.delete("\n") end |
#ordinal ⇒ Object
Access the Ordinal identifier property (if present)
26 |
# File 'lib/usps/imis/data.rb', line 26 def ordinal = self['Ordinal'] |
#pretty_print(pp) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/usps/imis/data.rb', line 44 def pretty_print(pp) data = { entity_type_name: raw['EntityTypeName'], imis_id:, ordinal: }.compact pp.group(1, "#<#{self.class}", '>') do data.each do |key, value| pp.breakable pp.text "#{key}=" pp.pp value end end end |