Class: UspsApi::Metadata1

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

Overview

Metadata containing information for pagination

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(total_count: SKIP, page: SKIP, total_pages: SKIP, offset: SKIP, limit: SKIP, links: SKIP, additional_properties: nil) ⇒ Metadata1

Returns a new instance of Metadata1.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/usps_api/models/metadata1.rb', line 68

def initialize(total_count: SKIP, page: SKIP, total_pages: SKIP,
               offset: SKIP, limit: SKIP, links: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @total_count = total_count unless total_count == SKIP
  @page = page unless page == SKIP
  @total_pages = total_pages unless total_pages == SKIP
  @offset = offset unless offset == SKIP
  @limit = limit unless limit == SKIP
  @links = links unless links == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#limitFloat

The number of service standard objects to return. Based on the user provided limit.

Returns:

  • (Float)


33
34
35
# File 'lib/usps_api/models/metadata1.rb', line 33

def limit
  @limit
end

Pagination navigation links.

Returns:



37
38
39
# File 'lib/usps_api/models/metadata1.rb', line 37

def links
  @links
end

#offsetFloat

The number of service standard objects to skip before returning the results. Based on the user provided offset.

Returns:

  • (Float)


28
29
30
# File 'lib/usps_api/models/metadata1.rb', line 28

def offset
  @offset
end

#pageFloat

The current page number.

Returns:

  • (Float)


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

def page
  @page
end

#total_countFloat

Total number of service standard objects to be returned in the API request (sum of all paginated results).

Returns:

  • (Float)


15
16
17
# File 'lib/usps_api/models/metadata1.rb', line 15

def total_count
  @total_count
end

#total_pagesFloat

Total number of pages, based on the user provided limit and totalCount.

Returns:

  • (Float)


23
24
25
# File 'lib/usps_api/models/metadata1.rb', line 23

def total_pages
  @total_pages
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/usps_api/models/metadata1.rb', line 84

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  total_count = hash.key?('totalCount') ? hash['totalCount'] : SKIP
  page = hash.key?('page') ? hash['page'] : SKIP
  total_pages = hash.key?('totalPages') ? hash['totalPages'] : SKIP
  offset = hash.key?('offset') ? hash['offset'] : SKIP
  limit = hash.key?('limit') ? hash['limit'] : SKIP
  links = Links.from_hash(hash['links']) if hash['links']

  # 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.
  Metadata1.new(total_count: total_count,
                page: page,
                total_pages: total_pages,
                offset: offset,
                limit: limit,
                links: links,
                additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



40
41
42
43
44
45
46
47
48
49
# File 'lib/usps_api/models/metadata1.rb', line 40

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['total_count'] = 'totalCount'
  @_hash['page'] = 'page'
  @_hash['total_pages'] = 'totalPages'
  @_hash['offset'] = 'offset'
  @_hash['limit'] = 'limit'
  @_hash['links'] = 'links'
  @_hash
end

.nullablesObject

An array for nullable fields



64
65
66
# File 'lib/usps_api/models/metadata1.rb', line 64

def self.nullables
  []
end

.optionalsObject

An array for optional fields



52
53
54
55
56
57
58
59
60
61
# File 'lib/usps_api/models/metadata1.rb', line 52

def self.optionals
  %w[
    total_count
    page
    total_pages
    offset
    limit
    links
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



121
122
123
124
125
126
# File 'lib/usps_api/models/metadata1.rb', line 121

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} total_count: #{@total_count.inspect}, page: #{@page.inspect}, total_pages:"\
  " #{@total_pages.inspect}, offset: #{@offset.inspect}, limit: #{@limit.inspect}, links:"\
  " #{@links.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



113
114
115
116
117
118
# File 'lib/usps_api/models/metadata1.rb', line 113

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} total_count: #{@total_count}, page: #{@page}, total_pages: #{@total_pages},"\
  " offset: #{@offset}, limit: #{@limit}, links: #{@links}, additional_properties:"\
  " #{@additional_properties}>"
end