Method: IPXACT::Parser::ComponentData.select_component

Defined in:
lib/ipxact/parser/component_data_parser.rb

.select_component(component_id, component_docs) ⇒ Component

Selects from the component_docs the component that corresponds to the component_id.

Parameters:

  • component_id (String, Array<String>)

    the component identifier, which should appear in one of the component_docs. This identifier can either be a String (in which circumstance the most recent component with the given name will be returned, if any) or an Array of 2 elements, composed as follows:

    [<component_identifier>, <component_version>]
    
  • component_docs (Hash<String, Nokogiri::Node>)

    the Hash of Nokogiri component documents that was extracted from the platform’s IPXACT specification.

Returns:

  • (Component)

    the component identified by component_id.

Raises:

  • (ArgumentError)

    if no component could be found.



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/ipxact/parser/component_data_parser.rb', line 114

def self.select_component(component_id, component_docs)
  if component_id.kind_of?(Array) && component_id.size == 2
    # A version must have been specified
    raise ArgumentError, "Component '#{component_id}' could not be found!" \
      unless component_docs.has_key? component_id 
    component_name, component_version = component_id
  else
    component_name = component_id
    component_version = component_docs.keys.select{|name, version| name == component_name} \
                                           .collect{|name, version| version} \
                                           .sort{|a, b| 
                                              1 if IPXACT::Identifier::is_most_recent_version?(a,b)
                                              0 if IPXACT::Identifier::is_same_version?(a,b)
                                              -1
                                           }.last
  end
  [component_name, component_version]
end