Class: Gdsii::Group

Inherits:
Object
  • Object
show all
Extended by:
Read
Defined in:
lib/gdsii/group.rb

Overview

Generic base class for a GDSII grouping of records (i.e. a boundary object and all records associated with it). This class will not be used directly but will be inherited by the various record groupings.

Direct Known Subclasses

Library, Properties, Property, Strans, Structure, Structures

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Read

read

Constructor Details

#initializeGroup

Constructor of a generic GDSII record grouping. Not intended to be called directly but rather from subclasses which inherit this class.



22
23
24
# File 'lib/gdsii/group.rb', line 22

def initialize()
  @records = BnfRecords.new(self.class)
end

Instance Attribute Details

#recordsObject (readonly)

Returns the value of attribute records.



16
17
18
# File 'lib/gdsii/group.rb', line 16

def records
  @records
end

Class Method Details

.bnf_keyObject

Get the BNF key for this class (default is the instantiating class)



92
# File 'lib/gdsii/group.rb', line 92

def bnf_key(); (@bnf_key.nil?) ? self : @bnf_key ; end

.bnf_key=(value) ⇒ Object

Set the BNF key for this class



89
# File 'lib/gdsii/group.rb', line 89

def bnf_key=(value); @bnf_key = value; end

.bnf_specObject

Return class bnf array



86
# File 'lib/gdsii/group.rb', line 86

def bnf_spec(); @bnf; end

.bnf_spec=(value) ⇒ Object

Set the class bnf array



83
# File 'lib/gdsii/group.rb', line 83

def bnf_spec=(value); @bnf = value; end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Simply yields itself for configuration (i.e. makes for prettier code). The object itself is returned.

Yields:

  • (_self)

Yield Parameters:

  • _self (Gdsii::Group)

    the object that the method was called on



30
31
32
33
# File 'lib/gdsii/group.rb', line 30

def configure()
  yield self
  self
end

#validateObject

Runs a code block to validate the object if the validate attribute is set. This is typically run to check record grouping integrity during read/write of GDSII files.



71
72
73
74
75
# File 'lib/gdsii/group.rb', line 71

def validate()
  if @validate
    @validate.call
  end
end

#write(file, alt_bnf = nil) ⇒ Object

Write the record grouping to a file. A file name as a String can be passed in which case a new file by the given name is opened in write mode (‘w’). Alternatively, a file object may be passed in which case the record grouping are written to the file object. Examples (assumes “object” has been initialized and descends from this class):

object.write('mydesign.gds')

or

# Note: 'wb' is required for DOS/Windows compatibility
File.open('otherdesign.gds', 'wb') do |file|
  object.write(file)
end


51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/gdsii/group.rb', line 51

def write(file, alt_bnf=nil)
  # If the file specified is a string, then open it up for writing. If it
  # is a file open it for writing if it is not already open
  if file.class == String
    file = File.open(file,"wb")
  elsif file.class == File
    file = File.open(file,"wb") if file.closed?
  else
    raise TypeError, "Invalid file object given: #{file}"
  end

  # Write to file according to BNF
  @records.write(file, alt_bnf)
end