Class: StarkInfra::Discount
- Inherits:
-
StarkCore::Utils::SubResource
- Object
- StarkCore::Utils::SubResource
- StarkInfra::Discount
- Defined in:
- lib/creditnote/invoice/discount.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. ex: ‘2020-03-10T10:30:00.000000+00:00’ or DateTime.new(2020, 3, 10, 10, 30, 0, 0).
Instance Attribute Summary collapse
-
#due ⇒ Object
readonly
Returns the value of attribute due.
-
#percentage ⇒ Object
readonly
Returns the value of attribute percentage.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(percentage:, due:) ⇒ Discount
constructor
A new instance of Discount.
Constructor Details
#initialize(percentage:, due:) ⇒ Discount
Returns a new instance of Discount.
17 18 19 20 |
# File 'lib/creditnote/invoice/discount.rb', line 17 def initialize(percentage:, due:) @percentage = percentage @due = due end |
Instance Attribute Details
#due ⇒ Object (readonly)
Returns the value of attribute due.
16 17 18 |
# File 'lib/creditnote/invoice/discount.rb', line 16 def due @due end |
#percentage ⇒ Object (readonly)
Returns the value of attribute percentage.
16 17 18 |
# File 'lib/creditnote/invoice/discount.rb', line 16 def percentage @percentage end |
Class Method Details
.parse_discounts(discounts) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/creditnote/invoice/discount.rb', line 22 def self.parse_discounts(discounts) resource_maker = StarkInfra::Discount.resource[:resource_maker] return discounts if discounts.nil? parsed_discounts = [] discounts.each do |discount| unless discount.is_a? Discount discount = StarkCore::Utils::API.from_api_json(resource_maker, discount) end parsed_discounts << discount end parsed_discounts end |
.resource ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/creditnote/invoice/discount.rb', line 36 def self.resource { resource_name: 'Discount', resource_maker: proc { |json| Discount.new( percentage: json['percentage'], due: json['due'] ) } } end |