Class: Usps::Imis::Data

Inherits:
BaseData show all
Defined in:
lib/usps/imis/data.rb

Overview

Convenience wrapper for accessing specific properties within an API data response

Instance Method Summary collapse

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

#entityObject

The Business Object or Panel name



15
# File 'lib/usps/imis/data.rb', line 15

def entity = raw['EntityTypeName']

#imis_idObject 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

#ordinalObject

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

Parameters:

  • include_ids (Boolean) (defaults to: false)

    Whether to include the iMIS ID and Ordinal



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