Class: EagleCAD::Board::Element

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, library, package, value, origin) ⇒ Element



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/eaglecad/board.rb', line 37

def initialize(name, library, package, value, origin)
    @name = name
    @library = library
    @package = package
    @value = value
    @origin = origin
    @locked = false
    @smashed = false
    @rotation = 0

    @attributes = []
    @variants = []
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



18
19
20
# File 'lib/eaglecad/board.rb', line 18

def attributes
  @attributes
end

#libraryObject

Returns the value of attribute library.



17
18
19
# File 'lib/eaglecad/board.rb', line 17

def library
  @library
end

#lockedObject

Returns the value of attribute locked.



17
18
19
# File 'lib/eaglecad/board.rb', line 17

def locked
  @locked
end

#nameObject

Returns the value of attribute name.



17
18
19
# File 'lib/eaglecad/board.rb', line 17

def name
  @name
end

#originObject

Returns the value of attribute origin.



17
18
19
# File 'lib/eaglecad/board.rb', line 17

def origin
  @origin
end

#packageObject

Returns the value of attribute package.



17
18
19
# File 'lib/eaglecad/board.rb', line 17

def package
  @package
end

#rotationObject

Returns the value of attribute rotation.



17
18
19
# File 'lib/eaglecad/board.rb', line 17

def rotation
  @rotation
end

#smashedObject

Returns the value of attribute smashed.



17
18
19
# File 'lib/eaglecad/board.rb', line 17

def smashed
  @smashed
end

#valueObject

Returns the value of attribute value.



17
18
19
# File 'lib/eaglecad/board.rb', line 17

def value
  @value
end

#variantsObject (readonly)

Returns the value of attribute variants.



18
19
20
# File 'lib/eaglecad/board.rb', line 18

def variants
  @variants
end

Class Method Details

.from_xml(element) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/eaglecad/board.rb', line 20

def self.from_xml(element)
    self.new(element.attributes['name'], element.attributes['library'], element.attributes['package'], element.attributes['value'], Geometry.point_from(element)).tap do |object|
 element.elements.each do |element|
      case element.name
  when 'attribute'
        object.attributes.push Attribute.from_xml(element)
  when 'variant'
        variants = {}
        element.attributes.each {|name, value| variants[name] = value }
        object.variants.push variants
  else
        raise StandardError, "Unrecognized Element element '#{element.name}'"
      end
 end
    end
end

Instance Method Details

#to_xmlREXML::Element



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/eaglecad/board.rb', line 52

def to_xml
    REXML::Element.new('element').tap do |element|
 element.add_attributes({'name' => name, 'library' => library, 'package' => package, 'value' => value, 'x' => origin.x, 'y' => origin.y})
 element.add_attribute('rot', "R#{rotation}") if 0 != rotation
 element.add_attribute('locked', 'yes') if locked
 element.add_attribute('smashed', 'yes') if smashed

 attributes.each {|attribute| element.add_element attribute.to_xml }
 variants.each {|variant| element.add_element('variant', variant)}
    end
end