Class: UspsApi::Metadata

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

Overview

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

Returns a new instance of Metadata.



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/usps_api/models/metadata.rb', line 59

def initialize(total_count: SKIP, page: SKIP, total_pages: SKIP,
               limit: SKIP, offset: 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
  @limit = limit unless limit == SKIP
  @offset = offset unless offset == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#limitInteger

The number of items per page.

Returns:

  • (Integer)


26
27
28
# File 'lib/usps_api/models/metadata.rb', line 26

def limit
  @limit
end

#offsetInteger

The offset of the current page.

Returns:

  • (Integer)


30
31
32
# File 'lib/usps_api/models/metadata.rb', line 30

def offset
  @offset
end

#pageInteger

The current page number.

Returns:

  • (Integer)


18
19
20
# File 'lib/usps_api/models/metadata.rb', line 18

def page
  @page
end

#total_countInteger

The total number of items.

Returns:

  • (Integer)


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

def total_count
  @total_count
end

#total_pagesInteger

The total number of pages.

Returns:

  • (Integer)


22
23
24
# File 'lib/usps_api/models/metadata.rb', line 22

def total_pages
  @total_pages
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/usps_api/models/metadata.rb', line 73

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
  limit = hash.key?('limit') ? hash['limit'] : SKIP
  offset = hash.key?('offset') ? hash['offset'] : SKIP

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

.namesObject

A mapping from model property names to API property names.



33
34
35
36
37
38
39
40
41
# File 'lib/usps_api/models/metadata.rb', line 33

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

.nullablesObject

An array for nullable fields



55
56
57
# File 'lib/usps_api/models/metadata.rb', line 55

def self.nullables
  []
end

.optionalsObject

An array for optional fields



44
45
46
47
48
49
50
51
52
# File 'lib/usps_api/models/metadata.rb', line 44

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

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



107
108
109
110
111
112
# File 'lib/usps_api/models/metadata.rb', line 107

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

#to_sObject

Provides a human-readable string representation of the object.



100
101
102
103
104
# File 'lib/usps_api/models/metadata.rb', line 100

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