Class: EagleCAD::DesignRules

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ DesignRules

Returns a new instance of DesignRules.



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

def initialize(name)
    @name = name
    @parameters = {}
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/eaglecad/design_rules.rb', line 5

def description
  @description
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/eaglecad/design_rules.rb', line 5

def name
  @name
end

#parametersObject (readonly)

Returns the value of attribute parameters.



6
7
8
# File 'lib/eaglecad/design_rules.rb', line 6

def parameters
  @parameters
end

Class Method Details

.from_xml(element) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/eaglecad/design_rules.rb', line 8

def self.from_xml(element)
    self.new(element.attributes['name']).tap do |rule|
	element.elements.each do |element|
	    case element.name
		when 'description'
		    rule.description = element.text
		when 'param'
		    rule.parameters[element.attributes['name']] = element.attributes['value']
		else
		    raise StandardError, "Unrecognized Design Rule element '#{element.name}'"
	    end
	end
    end
end

Instance Method Details

#to_xmlREXML::Element

Returns:

  • (REXML::Element)


29
30
31
32
33
34
35
36
# File 'lib/eaglecad/design_rules.rb', line 29

def to_xml
    REXML::Element.new('designrules').tap do |element|
	element.add_attribute 'name', name
	element.add_element('description').text = description if description

	parameters.each {|key, value| element.add_element('param', {'name' => key, 'value' => value})}
    end
end