Class: CDEKApiClient::Entities::Location

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

Overview

Represents a location in the CDEK API. Each location has attributes such as code, city, and address.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validatable

included, #validate!

Constructor Details

#initialize(code:, city: nil, address: nil) ⇒ Location

Initializes a new Location object.

Parameters:

  • code (Integer)

    the code of the location.

  • city (String, nil) (defaults to: nil)

    the city of the location.

  • address (String, nil) (defaults to: nil)

    the address of the location.

Raises:

  • (ArgumentError)

    if any attribute validation fails.



22
23
24
25
26
27
# File 'lib/cdek_api_client/entities/location.rb', line 22

def initialize(code:, city: nil, address: nil)
  @code = code
  @city = city
  @address = address
  validate!
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



10
11
12
# File 'lib/cdek_api_client/entities/location.rb', line 10

def address
  @address
end

#cityObject

Returns the value of attribute city.



10
11
12
# File 'lib/cdek_api_client/entities/location.rb', line 10

def city
  @city
end

#codeObject

Returns the value of attribute code.



10
11
12
# File 'lib/cdek_api_client/entities/location.rb', line 10

def code
  @code
end

Instance Method Details

#to_json(*_args) ⇒ String

Converts the Location object to a JSON representation.

Returns:

  • (String)

    the JSON representation of the Location.



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

def to_json(*_args)
  {
    code: @code,
    city: @city,
    address: @address
  }.to_json
end