Class: NewStoreApi::SalesOrderTotals

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/new_store_api/models/sales_order_totals.rb

Overview

SalesOrderTotals 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(discount = SKIP, gift_wrapping = SKIP, gross = SKIP, net = SKIP, shipping = SKIP, tax = SKIP, total = SKIP) ⇒ SalesOrderTotals

Returns a new instance of SalesOrderTotals.



72
73
74
75
76
77
78
79
80
81
# File 'lib/new_store_api/models/sales_order_totals.rb', line 72

def initialize(discount = SKIP, gift_wrapping = SKIP, gross = SKIP,
               net = SKIP, shipping = SKIP, tax = SKIP, total = SKIP)
  @discount = discount unless discount == SKIP
  @gift_wrapping = gift_wrapping unless gift_wrapping == SKIP
  @gross = gross unless gross == SKIP
  @net = net unless net == SKIP
  @shipping = shipping unless shipping == SKIP
  @tax = tax unless tax == SKIP
  @total = total unless total == SKIP
end

Instance Attribute Details

#discountFloat

The applied discount to the entire order.

Returns:

  • (Float)


14
15
16
# File 'lib/new_store_api/models/sales_order_totals.rb', line 14

def discount
  @discount
end

#gift_wrappingFloat

The amount paid for gift wrapping.

Returns:

  • (Float)


18
19
20
# File 'lib/new_store_api/models/sales_order_totals.rb', line 18

def gift_wrapping
  @gift_wrapping
end

#grossFloat

The gross price of the order, is the sum of all product item gross prices.

Returns:

  • (Float)


22
23
24
# File 'lib/new_store_api/models/sales_order_totals.rb', line 22

def gross
  @gross
end

#netFloat

The net price of the order, is the sum of all product item net prices.

Returns:

  • (Float)


26
27
28
# File 'lib/new_store_api/models/sales_order_totals.rb', line 26

def net
  @net
end

#shippingFloat

The shipping amount.

Returns:

  • (Float)


30
31
32
# File 'lib/new_store_api/models/sales_order_totals.rb', line 30

def shipping
  @shipping
end

#taxFloat

The taxes of the order, is the sum of all product item taxes.

Returns:

  • (Float)


34
35
36
# File 'lib/new_store_api/models/sales_order_totals.rb', line 34

def tax
  @tax
end

#totalFloat

The total amount that the customer paid including shipping costs, taxes, gift_wrapping and any discounts.

Returns:

  • (Float)


39
40
41
# File 'lib/new_store_api/models/sales_order_totals.rb', line 39

def total
  @total
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
# File 'lib/new_store_api/models/sales_order_totals.rb', line 84

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  discount = hash.key?('discount') ? hash['discount'] : SKIP
  gift_wrapping = hash.key?('gift_wrapping') ? hash['gift_wrapping'] : SKIP
  gross = hash.key?('gross') ? hash['gross'] : SKIP
  net = hash.key?('net') ? hash['net'] : SKIP
  shipping = hash.key?('shipping') ? hash['shipping'] : SKIP
  tax = hash.key?('tax') ? hash['tax'] : SKIP
  total = hash.key?('total') ? hash['total'] : SKIP

  # Create object from extracted values.
  SalesOrderTotals.new(discount,
                       gift_wrapping,
                       gross,
                       net,
                       shipping,
                       tax,
                       total)
end

.namesObject

A mapping from model property names to API property names.



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/new_store_api/models/sales_order_totals.rb', line 42

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['discount'] = 'discount'
  @_hash['gift_wrapping'] = 'gift_wrapping'
  @_hash['gross'] = 'gross'
  @_hash['net'] = 'net'
  @_hash['shipping'] = 'shipping'
  @_hash['tax'] = 'tax'
  @_hash['total'] = 'total'
  @_hash
end

.nullablesObject

An array for nullable fields



68
69
70
# File 'lib/new_store_api/models/sales_order_totals.rb', line 68

def self.nullables
  []
end

.optionalsObject

An array for optional fields



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/new_store_api/models/sales_order_totals.rb', line 55

def self.optionals
  %w[
    discount
    gift_wrapping
    gross
    net
    shipping
    tax
    total
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



114
115
116
117
118
119
# File 'lib/new_store_api/models/sales_order_totals.rb', line 114

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} discount: #{@discount.inspect}, gift_wrapping: #{@gift_wrapping.inspect},"\
  " gross: #{@gross.inspect}, net: #{@net.inspect}, shipping: #{@shipping.inspect}, tax:"\
  " #{@tax.inspect}, total: #{@total.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



107
108
109
110
111
# File 'lib/new_store_api/models/sales_order_totals.rb', line 107

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} discount: #{@discount}, gift_wrapping: #{@gift_wrapping}, gross: #{@gross},"\
  " net: #{@net}, shipping: #{@shipping}, tax: #{@tax}, total: #{@total}>"
end