Class: CDEKApiClient::Entities::Invoice
- Inherits:
-
Object
- Object
- CDEKApiClient::Entities::Invoice
- Includes:
- Validatable
- Defined in:
- lib/cdek_api_client/entities/invoice.rb
Overview
Represents an invoice entity for printing invoices in the CDEK API.
Instance Attribute Summary collapse
-
#copy_count ⇒ Object
Returns the value of attribute copy_count.
-
#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) ⇒ Invoice
Creates an Invoice with CDEK numbers.
-
.with_orders_uuid(orders_uuid) ⇒ Invoice
Creates an Invoice with orders UUIDs.
Instance Method Summary collapse
-
#initialize(orders:, copy_count: 1, type: nil) ⇒ Invoice
constructor
Initializes a new Invoice object.
-
#to_json(*_args) ⇒ String
Converts the Invoice object to a JSON representation.
Methods included from Validatable
Constructor Details
#initialize(orders:, copy_count: 1, type: nil) ⇒ Invoice
Initializes a new Invoice object.
23 24 25 26 27 28 |
# File 'lib/cdek_api_client/entities/invoice.rb', line 23 def initialize(orders:, copy_count: 1, type: nil) @orders = orders @copy_count = copy_count @type = type validate! end |
Instance Attribute Details
#copy_count ⇒ Object
Returns the value of attribute copy_count.
11 12 13 |
# File 'lib/cdek_api_client/entities/invoice.rb', line 11 def copy_count @copy_count end |
#orders ⇒ Object
Returns the value of attribute orders.
11 12 13 |
# File 'lib/cdek_api_client/entities/invoice.rb', line 11 def orders @orders end |
#type ⇒ Object
Returns the value of attribute type.
11 12 13 |
# File 'lib/cdek_api_client/entities/invoice.rb', line 11 def type @type end |
Class Method Details
.with_cdek_numbers(cdek_numbers) ⇒ Invoice
Creates an Invoice with CDEK numbers.
45 46 47 48 49 50 |
# File 'lib/cdek_api_client/entities/invoice.rb', line 45 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) ⇒ Invoice
Creates an Invoice with orders UUIDs.
34 35 36 37 38 39 |
# File 'lib/cdek_api_client/entities/invoice.rb', line 34 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 Invoice object to a JSON representation.
55 56 57 58 59 60 |
# File 'lib/cdek_api_client/entities/invoice.rb', line 55 def to_json(*_args) data = { orders: @orders } data[:copy_count] = @copy_count if @copy_count data[:type] = @type if @type data.to_json end |