Class: EagleCAD::Schematic
- Inherits:
-
Object
- Object
- EagleCAD::Schematic
- Defined in:
- lib/eaglecad/schematic.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
-
#description ⇒ Object
Returns the value of attribute description.
-
#libraries ⇒ Object
readonly
Returns the value of attribute libraries.
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
-
#sheets ⇒ Object
readonly
Returns the value of attribute sheets.
Class Method Summary collapse
-
.from_xml(element) ⇒ Object
Create a new Schematic from an REXML::Element.
Instance Method Summary collapse
-
#initialize ⇒ Schematic
constructor
A new instance of Schematic.
-
#to_xml ⇒ REXML::Element
Generate XML for the Schematic element.
Constructor Details
#initialize ⇒ Schematic
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
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
13 14 15 |
# File 'lib/eaglecad/schematic.rb', line 13 def attributes @attributes end |
#classes ⇒ Object (readonly)
Returns the value of attribute classes.
13 14 15 |
# File 'lib/eaglecad/schematic.rb', line 13 def classes @classes end |
#description ⇒ Object
Returns the value of attribute description.
12 13 14 |
# File 'lib/eaglecad/schematic.rb', line 12 def description @description end |
#libraries ⇒ Object (readonly)
Returns the value of attribute libraries.
13 14 15 |
# File 'lib/eaglecad/schematic.rb', line 13 def libraries @libraries end |
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
13 14 15 |
# File 'lib/eaglecad/schematic.rb', line 13 def parts @parts end |
#sheets ⇒ Object (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
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_xml ⇒ REXML::Element
Generate XML for the EagleCAD::Schematic 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 |