Class: NewStoreApi::FixedRateConfigCreateDto

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

Overview

FixedRateConfigCreateDto 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(tax_rate = nil, exemption_classes = SKIP, tax_name = SKIP) ⇒ FixedRateConfigCreateDto

Returns a new instance of FixedRateConfigCreateDto.



47
48
49
50
51
# File 'lib/new_store_api/models/fixed_rate_config_create_dto.rb', line 47

def initialize(tax_rate = nil, exemption_classes = SKIP, tax_name = SKIP)
  @exemption_classes = exemption_classes unless exemption_classes == SKIP
  @tax_name = tax_name unless tax_name == SKIP
  @tax_rate = tax_rate
end

Instance Attribute Details

#exemption_classesArray[ExemptionClassItemCreateDto]

A list of supported exemption classes.

Returns:



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

def exemption_classes
  @exemption_classes
end

#tax_nameString

Tax name to be used in the tax lines.

Returns:

  • (String)


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

def tax_name
  @tax_name
end

#tax_rateFloat

Tax rate to be used as a fixed rate during tax calculations.

  • Allows up to 5 decimal points.

Returns:

  • (Float)


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

def tax_rate
  @tax_rate
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/new_store_api/models/fixed_rate_config_create_dto.rb', line 54

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  tax_rate = hash.key?('tax_rate') ? hash['tax_rate'] : nil
  # Parameter is an array, so we need to iterate through it
  exemption_classes = nil
  unless hash['exemption_classes'].nil?
    exemption_classes = []
    hash['exemption_classes'].each do |structure|
      exemption_classes << (ExemptionClassItemCreateDto.from_hash(structure) if structure)
    end
  end

  exemption_classes = SKIP unless hash.key?('exemption_classes')
  tax_name = hash.key?('tax_name') ? hash['tax_name'] : SKIP

  # Create object from extracted values.
  FixedRateConfigCreateDto.new(tax_rate,
                               exemption_classes,
                               tax_name)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['exemption_classes'] = 'exemption_classes'
  @_hash['tax_name'] = 'tax_name'
  @_hash['tax_rate'] = 'tax_rate'
  @_hash
end

.nullablesObject

An array for nullable fields



43
44
45
# File 'lib/new_store_api/models/fixed_rate_config_create_dto.rb', line 43

def self.nullables
  []
end

.optionalsObject

An array for optional fields



35
36
37
38
39
40
# File 'lib/new_store_api/models/fixed_rate_config_create_dto.rb', line 35

def self.optionals
  %w[
    exemption_classes
    tax_name
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/new_store_api/models/fixed_rate_config_create_dto.rb', line 79

def self.validate(value)
  if value.instance_of? self
    return APIHelper.valid_type?(value.tax_rate,
                                 ->(val) { val.instance_of? Float })
  end

  return false unless value.instance_of? Hash

  APIHelper.valid_type?(value['tax_rate'],
                        ->(val) { val.instance_of? Float })
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



99
100
101
102
103
# File 'lib/new_store_api/models/fixed_rate_config_create_dto.rb', line 99

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

#to_sObject

Provides a human-readable string representation of the object.



92
93
94
95
96
# File 'lib/new_store_api/models/fixed_rate_config_create_dto.rb', line 92

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