Class: CDEKApiClient::Entities::TariffData

Inherits:
Object
  • Object
show all
Includes:
Validatable
Defined in:
lib/cdek_api_client/entities/tariff_data.rb

Overview

Represents the data required to calculate a tariff in the CDEK API. Each tariff data includes attributes such as type, currency, from_location, to_location, packages, and tariff_code.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validatable

included, #validate!

Constructor Details

#initialize(type:, currency:, from_location:, to_location:, packages:, tariff_code:) ⇒ TariffData

Initializes a new TariffData object.

Parameters:

  • type (Integer)

    the type of the tariff.

  • currency (String)

    the currency code of the tariff.

  • from_location (Location)

    the location from which the tariff calculation starts.

  • to_location (Location)

    the destination location for the tariff calculation.

  • packages (Array<Package>)

    the list of packages included in the tariff calculation.

  • tariff_code (Integer)

    the tariff code.

Raises:

  • (ArgumentError)

    if any attribute validation fails.



32
33
34
35
36
37
38
39
40
# File 'lib/cdek_api_client/entities/tariff_data.rb', line 32

def initialize(type:, currency:, from_location:, to_location:, packages:, tariff_code:)
  @type = type
  @currency = CurrencyMapper.to_code(currency)
  @from_location = from_location
  @to_location = to_location
  @packages = packages
  @tariff_code = tariff_code
  validate!
end

Instance Attribute Details

#currencyObject

Returns the value of attribute currency.



14
15
16
# File 'lib/cdek_api_client/entities/tariff_data.rb', line 14

def currency
  @currency
end

#from_locationObject

Returns the value of attribute from_location.



14
15
16
# File 'lib/cdek_api_client/entities/tariff_data.rb', line 14

def from_location
  @from_location
end

#packagesObject

Returns the value of attribute packages.



14
15
16
# File 'lib/cdek_api_client/entities/tariff_data.rb', line 14

def packages
  @packages
end

#tariff_codeObject

Returns the value of attribute tariff_code.



14
15
16
# File 'lib/cdek_api_client/entities/tariff_data.rb', line 14

def tariff_code
  @tariff_code
end

#to_locationObject

Returns the value of attribute to_location.



14
15
16
# File 'lib/cdek_api_client/entities/tariff_data.rb', line 14

def to_location
  @to_location
end

#typeObject

Returns the value of attribute type.



14
15
16
# File 'lib/cdek_api_client/entities/tariff_data.rb', line 14

def type
  @type
end

Instance Method Details

#to_json(*_args) ⇒ String

Converts the TariffData object to a JSON representation.

Returns:

  • (String)

    the JSON representation of the TariffData.



45
46
47
48
49
50
51
52
53
54
# File 'lib/cdek_api_client/entities/tariff_data.rb', line 45

def to_json(*_args)
  {
    type: @type,
    currency: @currency,
    from_location: @from_location,
    to_location: @to_location,
    packages: @packages,
    tariff_code: @tariff_code
  }.to_json
end