Class: TecDoc::AssemblyGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/tec_doc/assembly_group.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ AssemblyGroup

Returns a new instance of AssemblyGroup.



8
9
10
11
12
13
14
15
16
# File 'lib/tec_doc/assembly_group.rb', line 8

def initialize(attributes={})
  @id = attributes[:assembly_group_node_id].to_i
  @name = attributes[:assembly_group_name].to_s
  @has_children = attributes[:has_childs]
  @scope = attributes[:scope]
  if attributes[:parent_node_id]
    @parent_id = attributes[:parent_node_id].to_i
  end
end

Instance Attribute Details

#childrenObject



58
59
60
61
62
63
64
65
66
# File 'lib/tec_doc/assembly_group.rb', line 58

def children
  @children ||= if has_children
    self.class.
      all(scope.merge(:parent_node_id => id)).
      each { |child| child.parent = self }
  else
    []
  end
end

#has_childrenObject

Returns the value of attribute has_children.



3
4
5
# File 'lib/tec_doc/assembly_group.rb', line 3

def has_children
  @has_children
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/tec_doc/assembly_group.rb', line 3

def id
  @id
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/tec_doc/assembly_group.rb', line 3

def name
  @name
end

#parentObject

Returns the value of attribute parent.



3
4
5
# File 'lib/tec_doc/assembly_group.rb', line 3

def parent
  @parent
end

#parent_idObject

Returns the value of attribute parent_id.



3
4
5
# File 'lib/tec_doc/assembly_group.rb', line 3

def parent_id
  @parent_id
end

#scopeObject

Returns the value of attribute scope.



6
7
8
# File 'lib/tec_doc/assembly_group.rb', line 6

def scope
  @scope
end

Class Method Details

.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

Instance Method Details

#add_child(child) ⇒ Object



68
69
70
71
# File 'lib/tec_doc/assembly_group.rb', line 68

def add_child(child)
  @children ||= []
  @children << child
end

#inspectObject



73
74
75
# File 'lib/tec_doc/assembly_group.rb', line 73

def inspect
  "#<#{self.class} @id=#{id.inspect}, @parent_id=#{parent_id.inspect}, @name=#{name.inspect}, @has_children=#{has_children.inspect}>"
end