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, #initialize, to_class_name, to_symbol, value_types

Constructor Details

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

Instance Method Details

#[](k) ⇒ Object



345
346
347
# File 'lib/kicad/ast.rb', line 345

def [](k)
  property[k]
end

#[]=(k, v) ⇒ Object



349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# File 'lib/kicad/ast.rb', line 349

def []=(k, v)
  puts "Setting property #{k} to #{v.inspect}"
  if (p = property_node)
    p.send(:"#{self.class.to_symbol k}=", 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
end

#property(k = nil) ⇒ Object



337
338
339
340
341
342
343
# File 'lib/kicad/ast.rb', line 337

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



333
334
335
# File 'lib/kicad/ast.rb', line 333

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