Class: UspsApi::Service

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/usps_api/models/service.rb

Overview

Service Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(service: SKIP, hours: SKIP, additional_information: SKIP, additional_properties: nil) ⇒ Service

Returns a new instance of Service.



49
50
51
52
53
54
55
56
57
58
# File 'lib/usps_api/models/service.rb', line 49

def initialize(service: SKIP, hours: SKIP, additional_information: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @service = service unless service == SKIP
  @hours = hours unless hours == SKIP
  @additional_information = additional_information unless additional_information == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#additional_informationAdditionalInformation

the days & hours that the associated service is available at the post office.



24
25
26
# File 'lib/usps_api/models/service.rb', line 24

def additional_information
  @additional_information
end

#hoursArray[HoursOfOperation]

the days & hours that the associated service is available at the post office.

Returns:



19
20
21
# File 'lib/usps_api/models/service.rb', line 19

def hours
  @hours
end

#serviceString

The services supported at the facility.

Returns:

  • (String)


14
15
16
# File 'lib/usps_api/models/service.rb', line 14

def service
  @service
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/usps_api/models/service.rb', line 61

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  service = hash.key?('service') ? hash['service'] : SKIP
  # Parameter is an array, so we need to iterate through it
  hours = nil
  unless hash['hours'].nil?
    hours = []
    hash['hours'].each do |structure|
      hours << (HoursOfOperation.from_hash(structure) if structure)
    end
  end

  hours = SKIP unless hash.key?('hours')
  additional_information = AdditionalInformation.from_hash(hash['additionalInformation']) if
    hash['additionalInformation']

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  Service.new(service: service,
              hours: hours,
              additional_information: additional_information,
              additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



27
28
29
30
31
32
33
# File 'lib/usps_api/models/service.rb', line 27

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['service'] = 'service'
  @_hash['hours'] = 'hours'
  @_hash['additional_information'] = 'additionalInformation'
  @_hash
end

.nullablesObject

An array for nullable fields



45
46
47
# File 'lib/usps_api/models/service.rb', line 45

def self.nullables
  []
end

.optionalsObject

An array for optional fields



36
37
38
39
40
41
42
# File 'lib/usps_api/models/service.rb', line 36

def self.optionals
  %w[
    service
    hours
    additional_information
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



101
102
103
104
105
106
# File 'lib/usps_api/models/service.rb', line 101

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} service: #{@service.inspect}, hours: #{@hours.inspect},"\
  " additional_information: #{@additional_information.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



94
95
96
97
98
# File 'lib/usps_api/models/service.rb', line 94

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} service: #{@service}, hours: #{@hours}, additional_information:"\
  " #{@additional_information}, additional_properties: #{@additional_properties}>"
end