Class: EagleCAD::Attribute

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAttribute

Returns a new instance of Attribute.



25
26
27
28
# File 'lib/eaglecad/attribute.rb', line 25

def initialize
    super
    @display = 'value'
end

Instance Attribute Details

#constantObject

Returns the value of attribute constant

Returns:

  • (Object)

    the current value of constant



4
5
6
# File 'lib/eaglecad/attribute.rb', line 4

def constant
  @constant
end

#displayObject

Returns the value of attribute display

Returns:

  • (Object)

    the current value of display



4
5
6
# File 'lib/eaglecad/attribute.rb', line 4

def display
  @display
end

#fontObject

Returns the value of attribute font

Returns:

  • (Object)

    the current value of font



4
5
6
# File 'lib/eaglecad/attribute.rb', line 4

def font
  @font
end

#layer_numberObject

Returns the value of attribute layer_number

Returns:

  • (Object)

    the current value of layer_number



4
5
6
# File 'lib/eaglecad/attribute.rb', line 4

def layer_number
  @layer_number
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



4
5
6
# File 'lib/eaglecad/attribute.rb', line 4

def name
  @name
end

#originObject

Returns the value of attribute origin

Returns:

  • (Object)

    the current value of origin



4
5
6
# File 'lib/eaglecad/attribute.rb', line 4

def origin
  @origin
end

#ratioObject

Returns the value of attribute ratio

Returns:

  • (Object)

    the current value of ratio



4
5
6
# File 'lib/eaglecad/attribute.rb', line 4

def ratio
  @ratio
end

#rotationObject

Returns the value of attribute rotation

Returns:

  • (Object)

    the current value of rotation



4
5
6
# File 'lib/eaglecad/attribute.rb', line 4

def rotation
  @rotation
end

#sizeObject

Returns the value of attribute size

Returns:

  • (Object)

    the current value of size



4
5
6
# File 'lib/eaglecad/attribute.rb', line 4

def size
  @size
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



4
5
6
# File 'lib/eaglecad/attribute.rb', line 4

def value
  @value
end

Class Method Details

.from_xml(element) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/eaglecad/attribute.rb', line 5

def self.from_xml(element)
    Attribute.new.tap do |attribute|
	attribute.name = element.attributes['name']
	attribute.value = element.attributes['value']
	attribute.origin = Geometry.point_from(element)
	attribute.size = element.attributes['size']
	attribute.layer_number = element.attributes['layer']
	attribute.ratio = element.attributes['ratio'].to_i
	attribute.rotation = element.attributes['rot']

	element.attributes.each do |name, value|
	    case name
		when 'constant'	then attribute.constant = ('yes' == element.attribute['constant'])
		when 'display'	then attribute.display = value
		when 'font'	then attribute.font = value
	    end
	end
    end
end

Instance Method Details

#to_xmlREXML::Element

Returns:

  • (REXML::Element)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/eaglecad/attribute.rb', line 31

def to_xml
    REXML::Element.new('attribute').tap do |element|
	element.add_attribute('name', name)
	element.add_attribute('value', value)
	element.add_attribute('x', origin.x)
	element.add_attribute('y', origin.y)
	element.add_attribute('size', size)
	element.add_attribute('layer', layer_number)
	element.add_attribute('ratio', ratio) unless 0 == ratio
	element.add_attribute('rot', rotation)
	element.add_attribute('constant', 'yes') if constant
	element.add_attribute('display', display)
	element.add_attribute('font', font)
    end
end