Class: NewStoreApi::SalesOrderTaxLine

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

Overview

SalesOrderTaxLine 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(amount = nil, rate = nil, country_code = SKIP, name = SKIP) ⇒ SalesOrderTaxLine

Returns a new instance of SalesOrderTaxLine.



52
53
54
55
56
57
# File 'lib/new_store_api/models/sales_order_tax_line.rb', line 52

def initialize(amount = nil, rate = nil, country_code = SKIP, name = SKIP)
  @amount = amount
  @country_code = country_code unless country_code == SKIP
  @name = name unless name == SKIP
  @rate = rate
end

Instance Attribute Details

#amountFloat

Monetary tax amount for this line.

Returns:

  • (Float)


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

def amount
  @amount
end

#country_codeString

The code of the country of the tax in the ISO 3166 ALPHA-2 format. For example, GB, DE or US.

Returns:

  • (String)


19
20
21
# File 'lib/new_store_api/models/sales_order_tax_line.rb', line 19

def country_code
  @country_code
end

#nameString

Name of the tax line, e.g. MA Sales Tax.

Returns:

  • (String)


23
24
25
# File 'lib/new_store_api/models/sales_order_tax_line.rb', line 23

def name
  @name
end

#rateFloat

Decimal representation of the tax rate for this line, e.g. 6.25

Returns:

  • (Float)


27
28
29
# File 'lib/new_store_api/models/sales_order_tax_line.rb', line 27

def rate
  @rate
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/new_store_api/models/sales_order_tax_line.rb', line 60

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  amount = hash.key?('amount') ? hash['amount'] : nil
  rate = hash.key?('rate') ? hash['rate'] : nil
  country_code = hash.key?('country_code') ? hash['country_code'] : SKIP
  name = hash.key?('name') ? hash['name'] : SKIP

  # Create object from extracted values.
  SalesOrderTaxLine.new(amount,
                        rate,
                        country_code,
                        name)
end

.namesObject

A mapping from model property names to API property names.



30
31
32
33
34
35
36
37
# File 'lib/new_store_api/models/sales_order_tax_line.rb', line 30

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['amount'] = 'amount'
  @_hash['country_code'] = 'country_code'
  @_hash['name'] = 'name'
  @_hash['rate'] = 'rate'
  @_hash
end

.nullablesObject

An array for nullable fields



48
49
50
# File 'lib/new_store_api/models/sales_order_tax_line.rb', line 48

def self.nullables
  []
end

.optionalsObject

An array for optional fields



40
41
42
43
44
45
# File 'lib/new_store_api/models/sales_order_tax_line.rb', line 40

def self.optionals
  %w[
    country_code
    name
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



84
85
86
87
88
# File 'lib/new_store_api/models/sales_order_tax_line.rb', line 84

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

#to_sObject

Provides a human-readable string representation of the object.



77
78
79
80
81
# File 'lib/new_store_api/models/sales_order_tax_line.rb', line 77

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