Class: CDEKApiClient::Entities::Package

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

Overview

Represents a package entity in the CDEK API. Each package includes attributes such as number, comment, height, length, weight, width, and items.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validatable

included, #validate!

Constructor Details

#initialize(number:, comment:, height:, length:, weight:, width:, items:) ⇒ Package

Initializes a new Package object.

Parameters:

  • number (String)

    the package number.

  • comment (String)

    the comment for the package.

  • height (Integer)

    the height of the package.

  • length (Integer)

    the length of the package.

  • weight (Integer)

    the weight of the package.

  • width (Integer)

    the width of the package.

  • items (Array<Item>)

    the list of items in the package.

Raises:

  • (ArgumentError)

    if any attribute validation fails.



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

def initialize(number:, comment:, height:, length:, weight:, width:, items:)
  @number = number
  @comment = comment
  @height = height
  @length = length
  @weight = weight
  @width = width
  @items = items
  validate!
end

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



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

def comment
  @comment
end

#heightObject

Returns the value of attribute height.



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

def height
  @height
end

#itemsObject

Returns the value of attribute items.



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

def items
  @items
end

#lengthObject

Returns the value of attribute length.



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

def length
  @length
end

#numberObject

Returns the value of attribute number.



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

def number
  @number
end

#weightObject

Returns the value of attribute weight.



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

def weight
  @weight
end

#widthObject

Returns the value of attribute width.



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

def width
  @width
end

Instance Method Details

#to_json(*_args) ⇒ String

Converts the Package object to a JSON representation.

Returns:

  • (String)

    the JSON representation of the Package.



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

def to_json(*_args)
  {
    number: @number,
    comment: @comment,
    height: @height,
    length: @length,
    weight: @weight,
    width: @width,
    items: @items
  }.to_json
end