Class: EagleCAD::DeviceSet::Device

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Device

Returns a new instance of Device.



40
41
42
43
44
# File 'lib/eaglecad/deviceset.rb', line 40

def initialize(name)
		@connects = []
		@name = name
		@technologies = []
end

Instance Attribute Details

#connectsObject (readonly)

Returns the value of attribute connects.



23
24
25
# File 'lib/eaglecad/deviceset.rb', line 23

def connects
  @connects
end

#nameObject

Returns the value of attribute name.



22
23
24
# File 'lib/eaglecad/deviceset.rb', line 22

def name
  @name
end

#packageObject

Returns the value of attribute package.



22
23
24
# File 'lib/eaglecad/deviceset.rb', line 22

def package
  @package
end

#technologiesObject (readonly)

Returns the value of attribute technologies.



23
24
25
# File 'lib/eaglecad/deviceset.rb', line 23

def technologies
  @technologies
end

Class Method Details

.from_xml(element) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/eaglecad/deviceset.rb', line 25

def self.from_xml(element)
		Device.new(element.attributes['name']).tap do |device|
 device.package = element.attributes['package']

 element.elements.each do |element|
			case element.name
  when 'connects'
				element.elements.each {|connect| device.connects.push Connect.from_xml(connect) }
  when 'technologies'
				element.elements.each {|technology| device.technologies.push technology.attributes['name'] }
			end
 end
		end
end

Instance Method Details

#to_xmlREXML::Element

Generate XML for the EagleCAD::DeviceSet element

Returns:

  • (REXML::Element)


48
49
50
51
52
53
54
55
56
57
58
# File 'lib/eaglecad/deviceset.rb', line 48

def to_xml
		REXML::Element.new('device').tap do |element|
 element.add_attributes({'name' => name, 'package' => package})

 connects_element = element.add_element('connects')
 connects.each {|connect| connects_element.add_element connect.to_xml }

 technologies_element = element.add_element('technologies')
 technologies.each {|technology| technologies_element.add_element('technology', {'name' => technology}) }
		end
end