Class: EagleCAD::Schematic

Inherits:
Object
  • Object
show all
Defined in:
lib/eaglecad/schematic.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSchematic

Returns a new instance of Schematic.



41
42
43
44
45
46
47
# File 'lib/eaglecad/schematic.rb', line 41

def initialize
    @attributes = []
    @classes = []
    @libraries = {}
    @parts = []
    @sheets = []
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



13
14
15
# File 'lib/eaglecad/schematic.rb', line 13

def attributes
  @attributes
end

#classesObject (readonly)

Returns the value of attribute classes.



13
14
15
# File 'lib/eaglecad/schematic.rb', line 13

def classes
  @classes
end

#descriptionObject

Returns the value of attribute description.



12
13
14
# File 'lib/eaglecad/schematic.rb', line 12

def description
  @description
end

#librariesObject (readonly)

Returns the value of attribute libraries.



13
14
15
# File 'lib/eaglecad/schematic.rb', line 13

def libraries
  @libraries
end

#partsObject (readonly)

Returns the value of attribute parts.



13
14
15
# File 'lib/eaglecad/schematic.rb', line 13

def parts
  @parts
end

#sheetsObject (readonly)

Returns the value of attribute sheets.



13
14
15
# File 'lib/eaglecad/schematic.rb', line 13

def sheets
  @sheets
end

Class Method Details

.from_xml(element) ⇒ Object

Create a new EagleCAD::Schematic from an REXML::Element

Parameters:

  • element (REXML::Element)

    The REXML::Element to parse



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/eaglecad/schematic.rb', line 17

def self.from_xml(element)
    Schematic.new.tap do |schematic|
	element.elements.each do |element|
	    case element.name
		when 'attributes'
		    element.elements.each {|attribute| schematic.attributes.push Attribute.from_xml(attribute) }
		when 'classes'
		    element.elements.each {|clearance| schematic.classes.push Clearance.from_xml(clearance) }
		when 'description'
		    schematic.description = element.text
		when 'libraries'
		    element.elements.each {|library| schematic.libraries[library.attributes['name']] = Library.from_xml(library) }
		when 'parts'
		    element.elements.each {|part| schematic.parts.push Part.from_xml(part) }
		when 'sheets'
		    element.elements.each {|sheet| schematic.sheets.push Sheet.from_xml(sheet) }
		when 'variantdefs'
		else
		    raise StandardError, "Unrecognized element '#{element.name}'"
	    end
	end
    end
end

Instance Method Details

#to_xmlREXML::Element

Generate XML for the EagleCAD::Schematic element

Returns:

  • (REXML::Element)


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/eaglecad/schematic.rb', line 51

def to_xml
    REXML::Element.new('schematic').tap do |element|
	element.add_element('description').text = description if description

	# Libraries must be output before parts or Eagle will fail to load the file
	element.add_element('libraries').tap do |libraries_element|
	    libraries.each do |name, library|
		libraries_element.add_element library.to_xml
	    end
	end

	REXML::Element.new('attributes').tap do |attributes_element|
	    attributes.each {|attribute| attributes_element.add_element attribute.to_xml }
	    element.add_element(attributes_element) if attributes_element.has_elements?
	end

	element.add_element('variantdefs')

	element.add_element('classes').tap do |classes_element|
	    classes.each {|object| classes_element.add_element object.to_xml }
	end

	element.add_element('parts').tap do |parts_element|
	    parts.each {|part| parts_element.add_element part.to_xml }
	end

	element.add_element('sheets').tap do |sheets_element|
	    sheets.each {|sheet| sheets_element.add_element sheet.to_xml }
	end
    end
end