Class: EagleCAD::Attribute
- Inherits:
-
Struct
- Object
- Struct
- EagleCAD::Attribute
- Defined in:
- lib/eaglecad/attribute.rb
Instance Attribute Summary collapse
-
#constant ⇒ Object
Returns the value of attribute constant.
-
#display ⇒ Object
Returns the value of attribute display.
-
#font ⇒ Object
Returns the value of attribute font.
-
#layer_number ⇒ Object
Returns the value of attribute layer_number.
-
#name ⇒ Object
Returns the value of attribute name.
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#ratio ⇒ Object
Returns the value of attribute ratio.
-
#rotation ⇒ Object
Returns the value of attribute rotation.
-
#size ⇒ Object
Returns the value of attribute size.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Attribute
constructor
A new instance of Attribute.
- #to_xml ⇒ REXML::Element
Constructor Details
#initialize ⇒ Attribute
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
#constant ⇒ Object
Returns the value of attribute constant
4 5 6 |
# File 'lib/eaglecad/attribute.rb', line 4 def constant @constant end |
#display ⇒ Object
Returns the value of attribute display
4 5 6 |
# File 'lib/eaglecad/attribute.rb', line 4 def display @display end |
#font ⇒ Object
Returns the value of attribute font
4 5 6 |
# File 'lib/eaglecad/attribute.rb', line 4 def font @font end |
#layer_number ⇒ Object
Returns the value of attribute layer_number
4 5 6 |
# File 'lib/eaglecad/attribute.rb', line 4 def layer_number @layer_number end |
#name ⇒ Object
Returns the value of attribute name
4 5 6 |
# File 'lib/eaglecad/attribute.rb', line 4 def name @name end |
#origin ⇒ Object
Returns the value of attribute origin
4 5 6 |
# File 'lib/eaglecad/attribute.rb', line 4 def origin @origin end |
#ratio ⇒ Object
Returns the value of attribute ratio
4 5 6 |
# File 'lib/eaglecad/attribute.rb', line 4 def ratio @ratio end |
#rotation ⇒ Object
Returns the value of attribute rotation
4 5 6 |
# File 'lib/eaglecad/attribute.rb', line 4 def rotation @rotation end |
#size ⇒ Object
Returns the value of attribute size
4 5 6 |
# File 'lib/eaglecad/attribute.rb', line 4 def size @size end |
#value ⇒ Object
Returns the value of attribute 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_xml ⇒ 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 |