Class: EagleCAD::Layer

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, number, color, fill) ⇒ Layer

Returns a new instance of Layer.



18
19
20
21
22
23
24
25
# File 'lib/eaglecad/layer.rb', line 18

def initialize(name, number, color, fill)
    @active = true
    @color = color
    @fill = fill
    @name = name
    @number = number
    @visible = true
end

Instance Attribute Details

#activeObject

Returns the value of attribute active.



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

def active
  @active
end

#colorObject

Returns the value of attribute color.



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

def color
  @color
end

#fillObject

Returns the value of attribute fill.



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

def fill
  @fill
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#numberObject

Returns the value of attribute number.



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

def number
  @number
end

#visibleObject

Returns the value of attribute visible.



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

def visible
  @visible
end

Class Method Details

.from_xml(element) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/eaglecad/layer.rb', line 7

def self.from_xml(element)
    self.new(element.attributes['name'], element.attributes['number'], element.attributes['color'], element.attributes['fill']).tap do |layer|
	element.attributes.each do |name, value|
	    case name
		when 'active'	then layer.active = ('no' != value)
		when 'visible'	then layer.visible = ('no' != value)
	    end
	end
    end
end

Instance Method Details

#to_xmlREXML::Element

Returns:

  • (REXML::Element)


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

def to_xml
    element = REXML::Element.new 'layer'
    element.add_attributes({'number' => number,
			    'name' => name,
			    'color' => color,
			    'fill' => fill,
			   })
    element.add_attribute('active', active ? 'yes' : 'no')
    element.add_attribute('visible', visible ? 'yes' : 'no')
    element
end