Class: StarkInfra::Description

Inherits:
StarkCore::Utils::SubResource
  • Object
show all
Defined in:
lib/creditnote/invoice/description.rb

Overview

CreditNote::Invoice::Description object

Invoice description information.

## Parameters (required):

  • key [string]: Description for the value. ex: ‘Taxes’

## Parameters (optional):

  • value [string, default nil]: amount related to the described key. ex: ‘R$100,00’

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, value: nil) ⇒ Description

Returns a new instance of Description.



18
19
20
21
# File 'lib/creditnote/invoice/description.rb', line 18

def initialize(key:, value: nil)
  @key = key
  @value = value
end

Instance Attribute Details

#dueObject (readonly)

Returns the value of attribute due.



17
18
19
# File 'lib/creditnote/invoice/description.rb', line 17

def due
  @due
end

#percentageObject (readonly)

Returns the value of attribute percentage.



17
18
19
# File 'lib/creditnote/invoice/description.rb', line 17

def percentage
  @percentage
end

Class Method Details

.parse_descriptions(descriptions) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/creditnote/invoice/description.rb', line 23

def self.parse_descriptions(descriptions)
  resource_maker = StarkInfra::Description.resource[:resource_maker]
  return descriptions if descriptions.nil?

  parsed_descriptions = []
  descriptions.each do |description|
    unless description.is_a? Description
      description = StarkCore::Utils::API.from_api_json(resource_maker, description)
    end
    parsed_descriptions << description
  end
  parsed_descriptions
end

.resourceObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/creditnote/invoice/description.rb', line 37

def self.resource
  {
    resource_name: 'Description',
    resource_maker: proc { |json|
      Description.new(
        key: json['key'],
        value: json['value']
      )
    }
  }
end