Class: TecDoc::AssemblyGroup
- Inherits:
-
Object
- Object
- TecDoc::AssemblyGroup
- Defined in:
- lib/tec_doc/assembly_group.rb
Instance Attribute Summary collapse
- #children ⇒ Object
-
#has_children ⇒ Object
Returns the value of attribute has_children.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#parent_id ⇒ Object
Returns the value of attribute parent_id.
-
#scope ⇒ Object
Returns the value of attribute scope.
Class Method Summary collapse
-
.all(options = {}) ⇒ Array<TecDoc::AssemblyGroup>
Find vehicle, axle, motor or universal assembly groups for the search tree.
Instance Method Summary collapse
- #add_child(child) ⇒ Object
-
#initialize(attributes = {}) ⇒ AssemblyGroup
constructor
A new instance of AssemblyGroup.
- #inspect ⇒ Object
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
#children ⇒ Object
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_children ⇒ Object
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 |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/tec_doc/assembly_group.rb', line 3 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/tec_doc/assembly_group.rb', line 3 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
3 4 5 |
# File 'lib/tec_doc/assembly_group.rb', line 3 def parent @parent end |
#parent_id ⇒ Object
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 |
#scope ⇒ Object
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
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( = {}) = { :lang => I18n.locale.to_s }.merge() if [:linking_target_id] [:country] ||= TecDoc.client.country response = TecDoc.client.request(:get_linked_child_nodes_all_linking_target, ) else response = TecDoc.client.request(:get_child_nodes_all_linking_target2, ) end groups = response.map do |attributes| attributes[:scope] = new(attributes) end if [: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 |
#inspect ⇒ Object
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 |