Class: StarkInfra::CreditNote::Invoice::Discount

Inherits:
Utils::SubResource show all
Defined in:
lib/creditnote/creditnote.rb

Overview

# CreditNote::Invoice::Discount object

Invoice discount information.

## Parameters (required):

  • percentage [float]: percentage of discount applied until specified due date

  • due [DateTime or string]: due datetime for the discount

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Utils::SubResource

#inspect, #to_s

Constructor Details

#initialize(percentage:, due:) ⇒ Discount

Returns a new instance of Discount.



510
511
512
513
# File 'lib/creditnote/creditnote.rb', line 510

def initialize(percentage:, due:)
  @percentage = percentage
  @due = due
end

Instance Attribute Details

#dueObject (readonly)

Returns the value of attribute due.



509
510
511
# File 'lib/creditnote/creditnote.rb', line 509

def due
  @due
end

#percentageObject (readonly)

Returns the value of attribute percentage.



509
510
511
# File 'lib/creditnote/creditnote.rb', line 509

def percentage
  @percentage
end

Class Method Details

.parse_discounts(discounts) ⇒ Object



515
516
517
518
519
520
521
522
523
524
525
526
# File 'lib/creditnote/creditnote.rb', line 515

def self.parse_discounts(discounts)
  return discounts if discounts.nil?

  parsed_discounts = []
  discounts.each do |discount|
    unless discount.is_a? Discount
      discount = StarkInfra::Utils::API.from_api_json(resource[:resource_maker], discount)
    end
    parsed_discounts << discount
  end
  parsed_discounts
end

.resourceObject



528
529
530
531
532
533
534
535
536
537
538
# File 'lib/creditnote/creditnote.rb', line 528

def self.resource
  {
    resource_name: 'Discount',
    resource_maker: proc { |json|
      Discount.new(
        percentage: json['percentage'],
        due: json['due']
      )
    }
  }
end