Class: Sourcescrub::Models::CompanyItems

Inherits:
Entity
  • Object
show all
Defined in:
lib/sourcescrub/models/concerns/company_items.rb

Overview

Tag

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Entity

#as_json, #fields, #parse_response

Methods included from Utils::Response

dynamic_attributes

Instance Attribute Details

#identifierObject

Returns the value of attribute identifier.



8
9
10
# File 'lib/sourcescrub/models/concerns/company_items.rb', line 8

def identifier
  @identifier
end

#itemsObject

Returns the value of attribute items.



8
9
10
# File 'lib/sourcescrub/models/concerns/company_items.rb', line 8

def items
  @items
end

#totalObject

Returns the value of attribute total.



8
9
10
# File 'lib/sourcescrub/models/concerns/company_items.rb', line 8

def total
  @total
end

#typeObject

Returns the value of attribute type.



8
9
10
# File 'lib/sourcescrub/models/concerns/company_items.rb', line 8

def type
  @type
end

Instance Method Details

#parse_response_items(identifier, kclass_name, response) ⇒ Object

the identifier can be domain or SS ID



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sourcescrub/models/concerns/company_items.rb', line 11

def parse_response_items(identifier, kclass_name, response)
  headers = response.dig('headers')
  headers&.keys&.each do |attr_name|
    self.class.send(:define_method, attr_name.gsub('-', '_').to_sym) do
      headers[attr_name]
    end
  end

  dynamic_define_method(self, 'identifier', identifier)
  dynamic_define_method(self, 'type', kclass_name)
  dynamic_define_method(self, 'total', response.dig(total_key) || 0)
  dynamic_define_method(self, 'items', company_items(kclass_name, response.dig(items_key) || []))
  self
end