Method: TecDoc::AssemblyGroup.all

Defined in:
lib/tec_doc/assembly_group.rb

.all(options = {}) ⇒ Array<TecDoc::AssemblyGroup>

Find vehicle, axle, motor or universal assembly groups for the search tree

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :child_nodes (TrueClass, FalseClass)

    include child nodes

  • :lang (String)

    language code according to ISO 639

  • :linking_target_type (String)

    linking target (C: Vehicle type, M: Motor, A: Axle, K: Body Type, U: Universal)

  • :parent_node_id (Integer)

    parent node id (optional)

Returns:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/tec_doc/assembly_group.rb', line 25

def self.all(options = {})
  options = {
    :lang => I18n.locale.to_s
  }.merge(options)
  
  if options[:linking_target_id]
    options[:country] ||= TecDoc.client.country
    response = TecDoc.client.request(:get_linked_child_nodes_all_linking_target, options)
  else
    response = TecDoc.client.request(:get_child_nodes_all_linking_target2, options)
  end
  
  groups = response.map do |attributes|
    attributes[:scope] = options
    new(attributes)
  end
  
  if options[:child_nodes]
    group_ids_map = {}
    groups.each do |group|
      group_ids_map[group.id] = group
    end
    groups.each do |group|
      parent = group_ids_map[group.parent_id]
      if parent
        parent.add_child(group)
      end
    end
  end
  
  groups
end