Class: UspsApi::ItemCost

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

Overview

ItemCost 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(duty_price: SKIP, tax_price: SKIP, item_description: SKIP) ⇒ ItemCost

Returns a new instance of ItemCost.



48
49
50
51
52
# File 'lib/usps_api/models/item_cost.rb', line 48

def initialize(duty_price: SKIP, tax_price: SKIP, item_description: SKIP)
  @duty_price = duty_price unless duty_price == SKIP
  @tax_price = tax_price unless tax_price == SKIP
  @item_description = item_description unless item_description == SKIP
end

Instance Attribute Details

#duty_priceFloat

The value of the duties associated with the item.

Returns:

  • (Float)


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

def duty_price
  @duty_price
end

#item_descriptionString

The description of the item provided in ‘request.customsForm.contents[].itemDescription`.

Returns:

  • (String)


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

def item_description
  @item_description
end

#tax_priceFloat

The value of the taxes associated with the item.

Returns:

  • (Float)


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

def tax_price
  @tax_price
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/usps_api/models/item_cost.rb', line 55

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  duty_price = hash.key?('dutyPrice') ? hash['dutyPrice'] : SKIP
  tax_price = hash.key?('taxPrice') ? hash['taxPrice'] : SKIP
  item_description =
    hash.key?('itemDescription') ? hash['itemDescription'] : SKIP

  # Create object from extracted values.
  ItemCost.new(duty_price: duty_price,
               tax_price: tax_price,
               item_description: item_description)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['duty_price'] = 'dutyPrice'
  @_hash['tax_price'] = 'taxPrice'
  @_hash['item_description'] = 'itemDescription'
  @_hash
end

.nullablesObject

An array for nullable fields



44
45
46
# File 'lib/usps_api/models/item_cost.rb', line 44

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    duty_price
    tax_price
    item_description
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



78
79
80
81
82
# File 'lib/usps_api/models/item_cost.rb', line 78

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} duty_price: #{@duty_price.inspect}, tax_price: #{@tax_price.inspect},"\
  " item_description: #{@item_description.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



71
72
73
74
75
# File 'lib/usps_api/models/item_cost.rb', line 71

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} duty_price: #{@duty_price}, tax_price: #{@tax_price}, item_description:"\
  " #{@item_description}>"
end