Module: IPXACT::Parser::BusData

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

Overview

Module for parsing IPXACT bus XML data.

Author:

  • Guillaume Godet-Bar

Class Method Summary collapse

Class Method Details

.extract_bus_data(bus_doc, host_component, variables) ⇒ Array<Symbol, Object>

Extracts any relevant data from the bus_doc bus interface.

Parameters:

  • bus_doc (Nokogiri::Node)

    the bus interface’s IPXACT excerpt.

  • host_component (Nokogiri::Node)

    the bus interface’s host component IPXACT excerpt (i.e., Nokogiri Node).

  • variables (Array<Hash>)

    the list of variables that are associated to the host component instance.

Returns:

  • (Array<Symbol, Object>)

    an Array with the first element being the port type (i.e., :master, :mirrored_master, :slave or :mirrored_slave), and the second element being nil, a Hash, or an Array of Hashes, depending on the bus interface’s type.



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ipxact/parser/bus_data_parser.rb', line 65

def self.extract_bus_data(bus_doc, host_component, variables)
  if bus_doc.xpath("./spirit:mirroredMaster").size > 0
    [:mirrored_master, extract_mirrored_master_data]
  elsif bus_doc.xpath("./spirit:mirroredSlave").size > 0
    [:mirrored_slave, extract_mirrored_slave_data(bus_doc, host_component, variables)]
  elsif bus_doc.xpath("./spirit:slave").size > 0
    [:slave, extract_slave_data(bus_doc, host_component)]
  elsif bus_doc.xpath("./spirit:master").size > 0
    [:master, extract_master_data(bus_doc, host_component)]
  end
end

.parse_bus(bus_doc, host_component, variables) ⇒ Hash

Parses the bus_doc bus interface data.

Parameters:

  • bus_doc (Nokogiri::Node)

    the bus interface’s IPXACT excerpt.

  • host_component (Nokogiri::Node)

    the bus interface’s host component IPXACT excerpt.

  • variables (Array)

    the list of variables that are associated to the host component instance.

Returns:

  • (Hash)

    a Hash that describes the bus interface element. This Hash is composed of:

    :name       - The name of the port.
    :type       - The port type (i.e., :master, :mirrored_master, :slave or
                  :mirrored_slave)
    :bus_type   - The bus interface type (i.e., its generic name).
    :library    - The library in which the bus interface is defined.
    :port_data  - Specific port data, depending on the port type.
    


40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ipxact/parser/bus_data_parser.rb', line 40

def self.parse_bus(bus_doc, host_component, variables)
    port_type, port_data = extract_bus_data(bus_doc, host_component, variables)

    {
      :name => bus_doc.xpath("./spirit:name").first.text,
      :type => port_type,
      :bus_type => bus_doc.xpath("./spirit:busType").first['name'],
      :library => bus_doc.xpath("./spirit:busType").first['library'],
      :port_data => port_data
    }
end