Class: KiCad::AST::Symbol

Inherits:
Node
  • Object
show all
Defined in:
lib/kicad/ast.rb

Overview

Symbols

Instance Attribute Summary

Attributes inherited from Node

#children, #values

Instance Method Summary collapse

Methods inherited from Node

child_types, #children_of_type, #emit, #emit_compact, #emit_compacting, #initialize, to_class_name, to_symbol, value_types

Constructor Details

This class inherits a constructor from KiCad::AST::Node

Instance Method Details

#[](k) ⇒ Object



392
393
394
# File 'lib/kicad/ast.rb', line 392

def [](k)
  property[k]
end

#[]=(k, v) ⇒ Object



396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/kicad/ast.rb', line 396

def []=(k, v)
  # puts "Setting property #{k} to #{v.inspect}"
  if (prop = property_node(k))
    prop.value = v
  else  # Create new Property using the parser:
    prop = KiCad.parse(%Q{
      (property "#{k}" #{String === v ? v.inspect : v.to_s}
        (at 0 0 0)
        (effects(font(size 1.27 1.27)) (hide yes))
      )
    })&.value
    @children.append(prop) if prop
  end
  prop
end

#property(k = nil) ⇒ Object



384
385
386
387
388
389
390
# File 'lib/kicad/ast.rb', line 384

def property k = nil
  if k
    property_node(k)&.value
  else  # Return all properties as a Hash
    Hash[*self.all_property.map{|p| [p.key, p.value] }.flatten]
  end
end

#property_node(k) ⇒ Object

Get or set Property values by key, or as a Hash



380
381
382
# File 'lib/kicad/ast.rb', line 380

def property_node k
  self.all_property.detect{|p| p.key == k}
end