Class: CDEKApiClient::Entities::Service

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

Overview

Represents a service entity in the CDEK API. Each service includes attributes such as code, price, and name.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validatable

included, #validate!

Constructor Details

#initialize(code:, price:, name:) ⇒ Service

Initializes a new Service object.

Parameters:

  • code (String)

    the code of the service.

  • price (Integer)

    the price of the service.

  • name (String)

    the name of the service.

Raises:

  • (ArgumentError)

    if any attribute validation fails.



25
26
27
28
29
30
# File 'lib/cdek_api_client/entities/service.rb', line 25

def initialize(code:, price:, name:)
  @code = code
  @price = price
  @name = name
  validate!
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



13
14
15
# File 'lib/cdek_api_client/entities/service.rb', line 13

def code
  @code
end

#nameObject

Returns the value of attribute name.



13
14
15
# File 'lib/cdek_api_client/entities/service.rb', line 13

def name
  @name
end

#priceObject

Returns the value of attribute price.



13
14
15
# File 'lib/cdek_api_client/entities/service.rb', line 13

def price
  @price
end

Instance Method Details

#to_json(*_args) ⇒ String

Converts the Service object to a JSON representation.

Returns:

  • (String)

    the JSON representation of the Service.



35
36
37
38
39
40
41
# File 'lib/cdek_api_client/entities/service.rb', line 35

def to_json(*_args)
  {
    code: @code,
    price: @price,
    name: @name
  }.to_json
end