Class: EagleCAD::Sheet::Segment
- Inherits:
-
Object
- Object
- EagleCAD::Sheet::Segment
- Defined in:
- lib/eaglecad/sheet.rb
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#layers ⇒ Object
readonly
Returns the value of attribute layers.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Segment
constructor
A new instance of Segment.
-
#push(layer_number, element) ⇒ Object
Push a new element to the given layer number.
- #to_xml ⇒ Object
Constructor Details
#initialize ⇒ Segment
Returns a new instance of Segment.
169 170 171 172 173 |
# File 'lib/eaglecad/sheet.rb', line 169 def initialize @elements = [] @layers = {} @layers.default_proc = proc {|hash, key| hash[key] = []} end |
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
148 149 150 |
# File 'lib/eaglecad/sheet.rb', line 148 def elements @elements end |
#layers ⇒ Object (readonly)
Returns the value of attribute layers.
148 149 150 |
# File 'lib/eaglecad/sheet.rb', line 148 def layers @layers end |
Class Method Details
.from_xml(element) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/eaglecad/sheet.rb', line 150 def self.from_xml(element) Segment.new.tap do |segment| element.elements.each do |element| case element.name when 'junction' segment.elements.push Geometry.point_from(element) when 'label' segment.push element.attributes['layer'], Label.from_xml(element) when 'pinref' segment.elements.push PinReference.from_xml(element) when 'wire' segment.push element.attributes['layer'], Geometry::Line.from_xml(element) else raise StandardError, "Unrecognized Segment element '#{element.name}" end end end end |
Instance Method Details
#push(layer_number, element) ⇒ Object
Push a new element to the given layer number
178 179 180 181 |
# File 'lib/eaglecad/sheet.rb', line 178 def push(layer_number, element) layer = @layers[layer_number] layer.push element end |
#to_xml ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/eaglecad/sheet.rb', line 183 def to_xml REXML::Element.new('segment').tap do |element| elements.each do |object| if object.is_a? Point element.add_element('junction', {'x' => object.x, 'y' => object.y}) else element.add_element object.to_xml end end layers.each do |number, layer| layer.each {|obj| element.add_element(obj.to_xml, {'layer' => number}) } end end end |