Class: CDEKApiClient::Entities::Barcode
- Inherits:
-
Object
- Object
- CDEKApiClient::Entities::Barcode
- Includes:
- Validatable
- Defined in:
- lib/cdek_api_client/entities/barcode.rb
Overview
Represents a barcode entity for printing barcodes in the CDEK API.
Instance Attribute Summary collapse
-
#copy_count ⇒ Object
Returns the value of attribute copy_count.
-
#format ⇒ Object
Returns the value of attribute format.
-
#lang ⇒ Object
Returns the value of attribute lang.
-
#orders ⇒ Object
Returns the value of attribute orders.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
-
.with_cdek_numbers(cdek_numbers) ⇒ Barcode
Creates a Barcode with CDEK numbers.
-
.with_orders_uuid(orders_uuid) ⇒ Barcode
Creates a Barcode with orders UUIDs.
Instance Method Summary collapse
-
#initialize(orders:, copy_count: 1, type: nil, format: 'A4', lang: nil) ⇒ Barcode
constructor
Initializes a new Barcode object.
-
#to_json(*_args) ⇒ String
Converts the Barcode object to a JSON representation.
Methods included from Validatable
Constructor Details
#initialize(orders:, copy_count: 1, type: nil, format: 'A4', lang: nil) ⇒ Barcode
Initializes a new Barcode object.
27 28 29 30 31 32 33 34 |
# File 'lib/cdek_api_client/entities/barcode.rb', line 27 def initialize(orders:, copy_count: 1, type: nil, format: 'A4', lang: nil) @orders = orders @copy_count = copy_count @type = type @format = format @lang = lang validate! end |
Instance Attribute Details
#copy_count ⇒ Object
Returns the value of attribute copy_count.
11 12 13 |
# File 'lib/cdek_api_client/entities/barcode.rb', line 11 def copy_count @copy_count end |
#format ⇒ Object
Returns the value of attribute format.
11 12 13 |
# File 'lib/cdek_api_client/entities/barcode.rb', line 11 def format @format end |
#lang ⇒ Object
Returns the value of attribute lang.
11 12 13 |
# File 'lib/cdek_api_client/entities/barcode.rb', line 11 def lang @lang end |
#orders ⇒ Object
Returns the value of attribute orders.
11 12 13 |
# File 'lib/cdek_api_client/entities/barcode.rb', line 11 def orders @orders end |
#type ⇒ Object
Returns the value of attribute type.
11 12 13 |
# File 'lib/cdek_api_client/entities/barcode.rb', line 11 def type @type end |
Class Method Details
.with_cdek_numbers(cdek_numbers) ⇒ Barcode
Creates a Barcode with CDEK numbers.
51 52 53 54 55 56 |
# File 'lib/cdek_api_client/entities/barcode.rb', line 51 def self.with_cdek_numbers(cdek_numbers) orders = Array(cdek_numbers).map do |number| { cdek_number: number } end new(orders: orders) end |
.with_orders_uuid(orders_uuid) ⇒ Barcode
Creates a Barcode with orders UUIDs.
40 41 42 43 44 45 |
# File 'lib/cdek_api_client/entities/barcode.rb', line 40 def self.with_orders_uuid(orders_uuid) orders = Array(orders_uuid).map do |uuid| { order_uuid: uuid } end new(orders: orders) end |
Instance Method Details
#to_json(*_args) ⇒ String
Converts the Barcode object to a JSON representation.
61 62 63 64 65 66 67 68 |
# File 'lib/cdek_api_client/entities/barcode.rb', line 61 def to_json(*_args) data = { orders: @orders } data[:copy_count] = @copy_count if @copy_count data[:type] = @type if @type data[:format] = @format if @format data[:lang] = @lang if @lang data.to_json end |