Class: Portage::Ucp::Discounts

Inherits:
Data
  • Object
show all
Defined in:
lib/portage/ucp/value_objects.rb

Overview

schemas/shopping/discount.json#/$defs/discounts_object — codes is the request-side input (case-insensitive, full-replacement — send [] to clear); applied is the response-side result. Both optional, so a Cart/ Checkout with no discount activity omits the whole field (see Cart/ Checkout#to_wire_h below), same posture as Order#adjustments.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(codes: [], applied: []) ⇒ Discounts

Returns a new instance of Discounts.



363
# File 'lib/portage/ucp/value_objects.rb', line 363

def initialize(codes: [], applied: []) = super

Instance Attribute Details

#appliedObject (readonly)

Returns the value of attribute applied

Returns:

  • (Object)

    the current value of applied



362
363
364
# File 'lib/portage/ucp/value_objects.rb', line 362

def applied
  @applied
end

#codesObject (readonly)

Returns the value of attribute codes

Returns:

  • (Object)

    the current value of codes



362
363
364
# File 'lib/portage/ucp/value_objects.rb', line 362

def codes
  @codes
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


365
# File 'lib/portage/ucp/value_objects.rb', line 365

def empty? = codes.empty? && applied.empty?

#to_wire_hObject



367
368
369
370
371
372
# File 'lib/portage/ucp/value_objects.rb', line 367

def to_wire_h
  h = {}
  h["codes"] = codes unless codes.empty?
  h["applied"] = applied.map(&:to_wire_h) unless applied.empty?
  h
end