Class: NewStoreApi::TaxLine
- Defined in:
- lib/new_store_api/models/tax_line.rb
Overview
A single tax applied to a line item, itemising part of its price_tax.
Instance Attribute Summary collapse
-
#amount ⇒ Integer
The tax amount, in the currency's minor unit.
-
#country_code ⇒ String
The country of the tax in ISO 3166 ALPHA-2 format, e.g.
-
#name ⇒ String
A description of the tax type.
-
#rate ⇒ Float
The tax rate, as a ratio between 0 and 1 (not a percentage).
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
-
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
Instance Method Summary collapse
-
#initialize(amount = nil, name = nil, rate = nil, country_code = SKIP) ⇒ TaxLine
constructor
A new instance of TaxLine.
-
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
-
#to_s ⇒ Object
Provides a human-readable string representation of the object.
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, name = nil, rate = nil, country_code = SKIP) ⇒ TaxLine
Returns a new instance of TaxLine.
52 53 54 55 56 57 |
# File 'lib/new_store_api/models/tax_line.rb', line 52 def initialize(amount = nil, name = nil, rate = nil, country_code = SKIP) @amount = amount @country_code = country_code unless country_code == SKIP @name = name @rate = rate end |
Instance Attribute Details
#amount ⇒ Integer
The tax amount, in the currency's minor unit.
14 15 16 |
# File 'lib/new_store_api/models/tax_line.rb', line 14 def amount @amount end |
#country_code ⇒ String
The country of the tax in ISO 3166 ALPHA-2 format, e.g. GB, DE or US.
18 19 20 |
# File 'lib/new_store_api/models/tax_line.rb', line 18 def country_code @country_code end |
#name ⇒ String
A description of the tax type.
22 23 24 |
# File 'lib/new_store_api/models/tax_line.rb', line 22 def name @name end |
#rate ⇒ Float
The tax rate, as a ratio between 0 and 1 (not a percentage).
26 27 28 |
# File 'lib/new_store_api/models/tax_line.rb', line 26 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/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 name = hash.key?('name') ? hash['name'] : nil rate = hash.key?('rate') ? hash['rate'] : nil country_code = hash.key?('country_code') ? hash['country_code'] : SKIP # Create object from extracted values. TaxLine.new(amount, name, rate, country_code) end |
.names ⇒ Object
A mapping from model property names to API property names.
29 30 31 32 33 34 35 36 |
# File 'lib/new_store_api/models/tax_line.rb', line 29 def self.names @_hash = {} if @_hash.nil? @_hash['amount'] = 'amount' @_hash['country_code'] = 'country_code' @_hash['name'] = 'name' @_hash['rate'] = 'rate' @_hash end |
.nullables ⇒ Object
An array for nullable fields
46 47 48 49 50 |
# File 'lib/new_store_api/models/tax_line.rb', line 46 def self.nullables %w[ country_code ] end |
.optionals ⇒ Object
An array for optional fields
39 40 41 42 43 |
# File 'lib/new_store_api/models/tax_line.rb', line 39 def self.optionals %w[ country_code ] end |
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/new_store_api/models/tax_line.rb', line 78 def self.validate(value) if value.instance_of? self return ( APIHelper.valid_type?(value.amount, ->(val) { val.instance_of? Integer }) and APIHelper.valid_type?(value.name, ->(val) { val.instance_of? String }) and APIHelper.valid_type?(value.rate, ->(val) { val.instance_of? Float }) ) end return false unless value.instance_of? Hash ( APIHelper.valid_type?(value['amount'], ->(val) { val.instance_of? Integer }) and APIHelper.valid_type?(value['name'], ->(val) { val.instance_of? String }) and APIHelper.valid_type?(value['rate'], ->(val) { val.instance_of? Float }) ) end |
Instance Method Details
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
110 111 112 113 114 |
# File 'lib/new_store_api/models/tax_line.rb', line 110 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_s ⇒ Object
Provides a human-readable string representation of the object.
103 104 105 106 107 |
# File 'lib/new_store_api/models/tax_line.rb', line 103 def to_s class_name = self.class.name.split('::').last "<#{class_name} amount: #{@amount}, country_code: #{@country_code}, name: #{@name}, rate:"\ " #{@rate}>" end |