class EagleCAD::Board::Element
Attributes
attributes[R]
library[RW]
locked[RW]
name[RW]
origin[RW]
package[RW]
rotation[RW]
smashed[RW]
value[RW]
variants[R]
Public Class Methods
from_xml(element)
click to toggle source
# File lib/eaglecad/board.rb, line 20 def self.from_xml(element) self.new(element.attributes['name'], element.attributes['library'], element.attributes['package'], element.attributes['value'], Geometry.point_from(element)).tap do |object| element.elements.each do |element| case element.name when 'attribute' object.attributes.push Attribute.from_xml(element) when 'variant' variants = {} element.attributes.each {|name, value| variants[name] = value } object.variants.push variants else raise StandardError, "Unrecognized Element element '#{element.name}'" end end end end
new(name, library, package, value, origin)
click to toggle source
# File lib/eaglecad/board.rb, line 37 def initialize(name, library, package, value, origin) @name = name @library = library @package = package @value = value @origin = origin @locked = false @smashed = false @rotation = 0 @attributes = [] @variants = [] end
Public Instance Methods
to_xml()
click to toggle source
@return [REXML::Element]
# File lib/eaglecad/board.rb, line 52 def to_xml REXML::Element.new('element').tap do |element| element.add_attributes({'name' => name, 'library' => library, 'package' => package, 'value' => value, 'x' => origin.x, 'y' => origin.y}) element.add_attribute('rot', "R#{rotation}") if 0 != rotation element.add_attribute('locked', 'yes') if locked element.add_attribute('smashed', 'yes') if smashed attributes.each {|attribute| element.add_element attribute.to_xml } variants.each {|variant| element.add_element('variant', variant)} end end