Class: EagleCAD::Library
- Inherits:
-
Object
- Object
- EagleCAD::Library
- Defined in:
- lib/eaglecad/library.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#device_sets ⇒ Object
Returns the value of attribute device_sets.
-
#name ⇒ Object
Returns the value of attribute name.
-
#packages ⇒ Object
Returns the value of attribute packages.
-
#symbols ⇒ Object
Returns the value of attribute symbols.
Class Method Summary collapse
-
.from_xml(element) ⇒ Object
Create a new Library from an REXML::Element.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Library
constructor
A new instance of Library.
- #push(arg) ⇒ Object
-
#to_xml ⇒ REXML::Element
Generate XML for the Library element.
Constructor Details
#initialize(options = {}) ⇒ Library
Returns a new instance of Library.
30 31 32 33 34 35 36 |
# File 'lib/eaglecad/library.rb', line 30 def initialize(={}) .each {|k,v| send("#{k}=", v) } @device_sets = [] @packages = {} @symbols = [] end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
9 10 11 |
# File 'lib/eaglecad/library.rb', line 9 def description @description end |
#device_sets ⇒ Object
Returns the value of attribute device_sets.
9 10 11 |
# File 'lib/eaglecad/library.rb', line 9 def device_sets @device_sets end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/eaglecad/library.rb', line 9 def name @name end |
#packages ⇒ Object
Returns the value of attribute packages.
9 10 11 |
# File 'lib/eaglecad/library.rb', line 9 def packages @packages end |
#symbols ⇒ Object
Returns the value of attribute symbols.
9 10 11 |
# File 'lib/eaglecad/library.rb', line 9 def symbols @symbols end |
Class Method Details
.from_xml(element) ⇒ Object
Create a new EagleCAD::Library from an REXML::Element
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/eaglecad/library.rb', line 13 def self.from_xml(element) Library.new(name:element.attributes['name']).tap do |library| library.description = element.elements['description'] element.elements.each do |element| case element.name when 'devicesets' element.elements.each {|symbol| library.push DeviceSet.from_xml(symbol) } when 'packages' element.elements.each {|package| library.push Package.from_xml(package) } when 'symbols' element.elements.each {|symbol| library.push Symbol.from_xml(symbol) } end end end end |
Instance Method Details
#push(arg) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/eaglecad/library.rb', line 38 def push(arg) case arg when DeviceSet @device_sets.push arg when Package @packages[arg.name] = arg when Symbol @symbols.push arg end end |
#to_xml ⇒ REXML::Element
Generate XML for the EagleCAD::Library element
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/eaglecad/library.rb', line 51 def to_xml REXML::Element.new('library').tap do |element| element.add_attribute 'name', name # Packages must be output before devicesets or Eagle will fail to load the file element.add_element('packages').tap do |packages_element| packages.each {|name, package| packages_element.add_element package.to_xml } end # Symbols must be output before devicessets or Eagle will fail to load the file element.add_element('symbols').tap do |symbols_element| symbols.each {|symbol| symbols_element.add_element symbol.to_xml } end if device_sets and device_sets.count element.add_element('devicesets').tap do |devicesets_element| device_sets.each {|deviceset| devicesets_element.add_element deviceset.to_xml } end end end end |