Class: EagleCAD::Board::Element
- Inherits:
-
Object
- Object
- EagleCAD::Board::Element
- Defined in:
- lib/eaglecad/board.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#library ⇒ Object
Returns the value of attribute library.
-
#locked ⇒ Object
Returns the value of attribute locked.
-
#name ⇒ Object
Returns the value of attribute name.
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#package ⇒ Object
Returns the value of attribute package.
-
#rotation ⇒ Object
Returns the value of attribute rotation.
-
#smashed ⇒ Object
Returns the value of attribute smashed.
-
#value ⇒ Object
Returns the value of attribute value.
-
#variants ⇒ Object
readonly
Returns the value of attribute variants.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, library, package, value, origin) ⇒ Element
constructor
A new instance of Element.
- #to_xml ⇒ REXML::Element
Constructor Details
#initialize(name, library, package, value, origin) ⇒ Element
Returns a new instance of Element.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# 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 |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
18 19 20 |
# File 'lib/eaglecad/board.rb', line 18 def attributes @attributes end |
#library ⇒ Object
Returns the value of attribute library.
17 18 19 |
# File 'lib/eaglecad/board.rb', line 17 def library @library end |
#locked ⇒ Object
Returns the value of attribute locked.
17 18 19 |
# File 'lib/eaglecad/board.rb', line 17 def locked @locked end |
#name ⇒ Object
Returns the value of attribute name.
17 18 19 |
# File 'lib/eaglecad/board.rb', line 17 def name @name end |
#origin ⇒ Object
Returns the value of attribute origin.
17 18 19 |
# File 'lib/eaglecad/board.rb', line 17 def origin @origin end |
#package ⇒ Object
Returns the value of attribute package.
17 18 19 |
# File 'lib/eaglecad/board.rb', line 17 def package @package end |
#rotation ⇒ Object
Returns the value of attribute rotation.
17 18 19 |
# File 'lib/eaglecad/board.rb', line 17 def rotation @rotation end |
#smashed ⇒ Object
Returns the value of attribute smashed.
17 18 19 |
# File 'lib/eaglecad/board.rb', line 17 def smashed @smashed end |
#value ⇒ Object
Returns the value of attribute value.
17 18 19 |
# File 'lib/eaglecad/board.rb', line 17 def value @value end |
#variants ⇒ Object (readonly)
Returns the value of attribute variants.
18 19 20 |
# File 'lib/eaglecad/board.rb', line 18 def variants @variants end |
Class Method Details
.from_xml(element) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 |
Instance Method Details
#to_xml ⇒ REXML::Element
52 53 54 55 56 57 58 59 60 61 62 |
# 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 |