Class: EagleCAD::DeviceSet

Inherits:
Object
  • Object
show all
Defined in:
lib/eaglecad/deviceset.rb

Defined Under Namespace

Classes: Connect, Device, Gate

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#descriptionObject

Returns the value of attribute description.



7
8
9
# File 'lib/eaglecad/deviceset.rb', line 7

def description
  @description
end

#devicesObject (readonly)

Returns the value of attribute devices.



8
9
10
# File 'lib/eaglecad/deviceset.rb', line 8

def devices
  @devices
end

#gatesObject (readonly)

Returns the value of attribute gates.



8
9
10
# File 'lib/eaglecad/deviceset.rb', line 8

def gates
  @gates
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/eaglecad/deviceset.rb', line 7

def name
  @name
end

#prefixObject

Returns the value of attribute prefix.



7
8
9
# File 'lib/eaglecad/deviceset.rb', line 7

def prefix
  @prefix
end

#uservalueObject

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

Parameters:

  • element (Element)

    The REXML::Element to parse



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_xmlREXML::Element

Generate XML for the EagleCAD::DeviceSet element

Returns:

  • (REXML::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