Class: EagleCAD::Package
- Inherits:
-
Object
- Object
- EagleCAD::Package
- Defined in:
- lib/eaglecad/package.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#holes ⇒ Object
readonly
Returns the value of attribute holes.
-
#layers ⇒ Object
readonly
Returns the value of attribute layers.
-
#name ⇒ Object
Returns the value of attribute name.
-
#pads ⇒ Object
readonly
Returns the value of attribute pads.
Class Method Summary collapse
-
.from_xml(element) ⇒ Object
Create a new Package from an REXML::Element.
Instance Method Summary collapse
-
#initialize(name) ⇒ Package
constructor
A new instance of Package.
-
#push(layer_number, element) ⇒ Object
Push a new element to the given layer number.
-
#to_xml ⇒ REXML::Element
Generate XML for the Package element.
Constructor Details
#initialize(name) ⇒ Package
Returns a new instance of Package.
41 42 43 44 45 46 47 |
# File 'lib/eaglecad/package.rb', line 41 def initialize(name) @holes = [] @layers = {} @layers.default_proc = proc {|hash, key| hash[key] = []} @name = name @pads = [] end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
10 11 12 |
# File 'lib/eaglecad/package.rb', line 10 def description @description end |
#holes ⇒ Object (readonly)
Returns the value of attribute holes.
11 12 13 |
# File 'lib/eaglecad/package.rb', line 11 def holes @holes end |
#layers ⇒ Object (readonly)
Returns the value of attribute layers.
11 12 13 |
# File 'lib/eaglecad/package.rb', line 11 def layers @layers end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/eaglecad/package.rb', line 10 def name @name end |
#pads ⇒ Object (readonly)
Returns the value of attribute pads.
11 12 13 |
# File 'lib/eaglecad/package.rb', line 11 def pads @pads end |
Class Method Details
.from_xml(element) ⇒ Object
Create a new EagleCAD::Package from an REXML::Element
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/eaglecad/package.rb', line 15 def self.from_xml(element) package = Package.new element.attributes['name'] element.elements.each do |element| layer_number = element.attributes['layer'].to_i if element.attributes.has_key?('layer') case element.name when 'description' package.description = element.text when 'hole' package.holes.push Geometry::Hole.from_xml(element) when 'pad' package.pads.push Geometry::Pad.from_xml(element) else g = Geometry.from_xml(element) if g package.push layer_number, g else raise StandardError, "Unrecognized package element '#{element.name}'" end end end package end |
Instance Method Details
#push(layer_number, element) ⇒ Object
Push a new element to the given layer number
52 53 54 55 |
# File 'lib/eaglecad/package.rb', line 52 def push(layer_number, element) layer = @layers[layer_number] layer.push element end |
#to_xml ⇒ REXML::Element
Generate XML for the EagleCAD::Package element
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/eaglecad/package.rb', line 59 def to_xml REXML::Element.new('package').tap do |element| element.add_attribute('name', name) element.add_element('description').text = description holes.each {|hole| element.add_element hole.to_xml } pads.each {|pad| element.add_element pad.to_xml } layers.each do |number, layer| layer.each {|obj| element.add_element(obj.to_xml, {'layer' => number}) } end end end |