Class: Portage::Ucp::AppliedDiscount

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

Overview

schemas/shopping/discount.json#/$defs/applied_discount — requires title/ amount. code is omitted for automatic discounts; allocations (the per-target breakdown) is left empty rather than guessed at by adapters that can't source it from their platform. allocation_method maps to the wire key "method" — bare :method as a Data.define member would shadow Kernel#method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title:, amount:, code: nil, automatic: false, allocation_method: nil, priority: nil, provisional: false, eligibility: nil, allocations: []) ⇒ AppliedDiscount

Returns a new instance of AppliedDiscount.



220
221
222
223
# File 'lib/portage/ucp/value_objects.rb', line 220

def initialize(title:, amount:, code: nil, automatic: false, allocation_method: nil, priority: nil,
               provisional: false, eligibility: nil, allocations: [])
  super
end

Instance Attribute Details

#allocation_methodObject (readonly)

Returns the value of attribute allocation_method

Returns:

  • (Object)

    the current value of allocation_method



218
219
220
# File 'lib/portage/ucp/value_objects.rb', line 218

def allocation_method
  @allocation_method
end

#allocationsObject (readonly)

Returns the value of attribute allocations

Returns:

  • (Object)

    the current value of allocations



218
219
220
# File 'lib/portage/ucp/value_objects.rb', line 218

def allocations
  @allocations
end

#amountObject (readonly)

Returns the value of attribute amount

Returns:

  • (Object)

    the current value of amount



218
219
220
# File 'lib/portage/ucp/value_objects.rb', line 218

def amount
  @amount
end

#automaticObject (readonly)

Returns the value of attribute automatic

Returns:

  • (Object)

    the current value of automatic



218
219
220
# File 'lib/portage/ucp/value_objects.rb', line 218

def automatic
  @automatic
end

#codeObject (readonly)

Returns the value of attribute code

Returns:

  • (Object)

    the current value of code



218
219
220
# File 'lib/portage/ucp/value_objects.rb', line 218

def code
  @code
end

#eligibilityObject (readonly)

Returns the value of attribute eligibility

Returns:

  • (Object)

    the current value of eligibility



218
219
220
# File 'lib/portage/ucp/value_objects.rb', line 218

def eligibility
  @eligibility
end

#priorityObject (readonly)

Returns the value of attribute priority

Returns:

  • (Object)

    the current value of priority



218
219
220
# File 'lib/portage/ucp/value_objects.rb', line 218

def priority
  @priority
end

#provisionalObject (readonly)

Returns the value of attribute provisional

Returns:

  • (Object)

    the current value of provisional



218
219
220
# File 'lib/portage/ucp/value_objects.rb', line 218

def provisional
  @provisional
end

#titleObject (readonly)

Returns the value of attribute title

Returns:

  • (Object)

    the current value of title



218
219
220
# File 'lib/portage/ucp/value_objects.rb', line 218

def title
  @title
end

Instance Method Details

#to_wire_hObject



225
226
227
228
229
230
231
232
233
# File 'lib/portage/ucp/value_objects.rb', line 225

def to_wire_h
  h = { "title" => title, "amount" => amount }
  { code: "code", automatic: "automatic", allocation_method: "method", priority: "priority",
    provisional: "provisional", eligibility: "eligibility" }.each do |attr, key|
    h[key] = public_send(attr) if public_send(attr)
  end
  h["allocations"] = allocations if allocations.any?
  h
end