Class: EagleCAD::DeviceSet
- Inherits:
-
Object
- Object
- EagleCAD::DeviceSet
- Defined in:
- lib/eaglecad/deviceset.rb
Defined Under Namespace
Classes: Connect, Device, Gate
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#devices ⇒ Object
readonly
Returns the value of attribute devices.
-
#gates ⇒ Object
readonly
Returns the value of attribute gates.
-
#name ⇒ Object
Returns the value of attribute name.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#uservalue ⇒ Object
Returns the value of attribute uservalue.
Class Method Summary collapse
-
.from_xml(element) ⇒ Object
Create a new DeviceSet from an REXML::Element.
Instance Method Summary collapse
-
#initialize(name) ⇒ DeviceSet
constructor
A new instance of DeviceSet.
-
#to_xml ⇒ REXML::Element
Generate XML for the DeviceSet element.
Constructor Details
#initialize(name) ⇒ DeviceSet
Returns a new instance of DeviceSet.
92 93 94 95 96 |
# File 'lib/eaglecad/deviceset.rb', line 92 def initialize(name) @devices = [] @gates = [] @name = name end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
7 8 9 |
# File 'lib/eaglecad/deviceset.rb', line 7 def description @description end |
#devices ⇒ Object (readonly)
Returns the value of attribute devices.
8 9 10 |
# File 'lib/eaglecad/deviceset.rb', line 8 def devices @devices end |
#gates ⇒ Object (readonly)
Returns the value of attribute gates.
8 9 10 |
# File 'lib/eaglecad/deviceset.rb', line 8 def gates @gates end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/eaglecad/deviceset.rb', line 7 def name @name end |
#prefix ⇒ Object
Returns the value of attribute prefix.
7 8 9 |
# File 'lib/eaglecad/deviceset.rb', line 7 def prefix @prefix end |
#uservalue ⇒ Object
Returns the value of attribute uservalue.
7 8 9 |
# File 'lib/eaglecad/deviceset.rb', line 7 def uservalue @uservalue end |
Class Method Details
.from_xml(element) ⇒ Object
Create a new EagleCAD::DeviceSet from an REXML::Element
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/eaglecad/deviceset.rb', line 74 def self.from_xml(element) DeviceSet.new(element.attributes['name']).tap do |deviceset| deviceset.prefix = element.attributes['prefix'] deviceset.uservalue = ('yes' == element.attributes['uservalue']) element.elements.each do |element| case element.name when 'devices' element.elements.each {|device| deviceset.devices.push Device.from_xml(device) } when 'description' deviceset.description = element.text when 'gates' element.elements.each {|gate| deviceset.gates.push Gate.from_xml(gate) } end end end end |
Instance Method Details
#to_xml ⇒ REXML::Element
Generate XML for the EagleCAD::DeviceSet element
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/eaglecad/deviceset.rb', line 100 def to_xml REXML::Element.new('deviceset').tap do |element| element.add_attributes({'name' => name, 'prefix' => prefix, 'uservalue' => (uservalue ? 'yes' : 'no')}) element.add_element('description').text = description gates_element = element.add_element('gates') gates.each {|gate| gates_element.add_element gate.to_xml } devices_element = element.add_element('devices') devices.each {|device| devices_element.add_element device.to_xml } end end |