Class: EagleCAD::Sheet::Instance
- Inherits:
-
Object
- Object
- EagleCAD::Sheet::Instance
- Defined in:
- lib/eaglecad/sheet.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#gate ⇒ Object
Returns the value of attribute gate.
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#part ⇒ Object
Returns the value of attribute part.
-
#rotation ⇒ Object
Returns the value of attribute rotation.
-
#smashed ⇒ Object
Returns the value of attribute smashed.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(part, gate, origin) ⇒ Instance
constructor
A new instance of Instance.
- #to_xml ⇒ Object
Constructor Details
#initialize(part, gate, origin) ⇒ Instance
Returns a new instance of Instance.
64 65 66 67 68 69 70 71 |
# File 'lib/eaglecad/sheet.rb', line 64 def initialize(part, gate, origin) @attributes = [] @part = part @gate = gate @origin = origin @smashed = false @rotation = 'R0' end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
46 47 48 |
# File 'lib/eaglecad/sheet.rb', line 46 def attributes @attributes end |
#gate ⇒ Object
Returns the value of attribute gate.
45 46 47 |
# File 'lib/eaglecad/sheet.rb', line 45 def gate @gate end |
#origin ⇒ Object
Returns the value of attribute origin.
45 46 47 |
# File 'lib/eaglecad/sheet.rb', line 45 def origin @origin end |
#part ⇒ Object
Returns the value of attribute part.
45 46 47 |
# File 'lib/eaglecad/sheet.rb', line 45 def part @part end |
#rotation ⇒ Object
Returns the value of attribute rotation.
45 46 47 |
# File 'lib/eaglecad/sheet.rb', line 45 def rotation @rotation end |
#smashed ⇒ Object
Returns the value of attribute smashed.
45 46 47 |
# File 'lib/eaglecad/sheet.rb', line 45 def smashed @smashed end |
Class Method Details
.from_xml(element) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/eaglecad/sheet.rb', line 48 def self.from_xml(element) Instance.new(element.attributes['part'], element.attributes['gate'], Geometry.point_from(element)).tap do |instance| element.attributes.each do |name, value| case name when 'smashed' then instance.smashed = ('no' != element.attributes['smashed']) when 'rot' then instance.rotation = element.attributes['rot'] when 'part', 'gate', 'x', 'y' # Ignore; already handled else raise StandardError, "Unrecognized Instance attribute '#{name}'" end end element.elements.each {|attribute| instance.attributes.push Attribute.from_xml(attribute) } end end |
Instance Method Details
#to_xml ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/eaglecad/sheet.rb', line 73 def to_xml REXML::Element.new('instance').tap do |element| element.add_attributes({'part' => part, 'gate' => gate, 'x' => origin.x, 'y' => origin.y}) element.add_attribute('smashed', 'yes') if smashed element.add_attribute('rot', rotation) attributes.each {|attribute| element.add_element attribute.to_xml } end end |