require "AP233_ARM_LF"
require 'rexml/document'
include REXML
include AP233
##
## ALL creation of AP233 instance data needs to be prefixed by AP233::
##
## This example shows how to use the AP233 Ruby API.
##
## Create a model container for the data instances. Always use the ap233 namespace.
## Set the model_name to be anything you want. You can create more than one model.
## A model equates to an XML file when output.
## Use the model_elements list to hold pointers to the instances included in the model.
m = AP233::Model___data.new
m.namespace = "ap233"
m.model_name = "Test dataset 1"
##
## Create a Requirement. The format is AP233::<class name>.<operation>
## r1 is the pointer to the new Requirement instance.
r1 = AP233::Requirement.new
##
## Set the name attribute for instance number 1
r1.name = "Requirement 1"
##
## Put the Requirement instance number 1 in the model container using the model_elements list.
m.model_elements = [r1]
##
## Create and assign an External_class to the Requirement instance
lib233 = AP233::External_class_library.new
m.model_elements.push lib233
lib233.id = "http://www.iso.org/10303/233"
lib233.description = "The ISO Standard 10303-233 AP233 Systems Engineering Class Library"
unclassified = AP233::External_class.new
m.model_elements.push unclassified
unclassified.id = "http://www.iso.org/10303/233#unclassified"
unclassified.name = "Unclassified"
unclassified.external_source = lib233
## Assign the Requirement as being Unclassified
uncassign = AP233::Classification_assignment.new
m.model_elements.push uncassign
uncassign.assigned_class = unclassified
uncassign.items = [r1]
##
## Create a Requirement_version instance and associate it with the Requirement instance 1
## Remember that Requirement_version is a kind of Product_version and for XML the referring relationship
## cannot be renamed so it is called of_product.
rv1 = AP233::Requirement_version.new
m.model_elements.push rv1
rv1.id = "V1"
rv1.of_product = r1
##
## Create a second Requirement, give it a name and push it onto the model_elements list
r2 = AP233::Requirement.new
r2.name = "Requirement 2"
m.model_elements.push r2
uncassign.items.push r2
##
## Create a second Requirement_version instance and associate it with the Requirement instance 2.
## Note how you don't have to create a separate variable for the pointer in this case.
## We can use the Ruby array method called last to refer to the pointer we just added to the model_elements.
m.model_elements.push AP233::Requirement_version.new
m.model_elements.last.id = "V1"
m.model_elements.last.of_product = r2
##
## Create a File, give it an id and push in onto the model_elements list.
f1 = AP233::File.new
f1.id = "My File"
m.model_elements.push f1
##
## Set up the XML file and write all data in the model container to the file. Only change the File name.
datafile = File.new("data.xml","w")
p28file = REXML::Document.new
m.writeP28e2 p28file
datafile.puts p28file
datafile.close
