Class: Gdsii::BnfSpec

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/gdsii/bnf.rb

Overview

This class represents the order of a GDSII record grouping using a specific record order in Backus-Naur Form (BNF). It consists of a number of BnfItem objects where the order of the items is important in determining the order in which the GDSII file format should be read or written from/to a file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*bnf_items) ⇒ BnfSpec

Creates a Backus-Naur Form (BNF) grouping consisting of BnfItem objects.

spec = BnfSpec.new(
  BnfItem.new(GRT_PROPATTR),
  BnfItem.new(GRT_PROPVALUE)
)


75
76
77
# File 'lib/gdsii/bnf.rb', line 75

def initialize(*bnf_items)
  @bnf_items = bnf_items
end

Instance Attribute Details

#bnf_itemsObject (readonly)

Returns the value of attribute bnf_items.



65
66
67
# File 'lib/gdsii/bnf.rb', line 65

def bnf_items
  @bnf_items
end

Instance Method Details

#[](key) ⇒ Object

Shortcut for #find_item but will raise an exception if the item key is not part of this BNF.

spec = ...
spec.find_item(GRT_PROPATTR)  #=> BnfItem ...
spec.find_item(GRT_HEADER)    #=> raise IndexError ...


110
111
112
113
114
115
116
# File 'lib/gdsii/bnf.rb', line 110

def [](key)
  if (found = find_item(key))
    found
  else
    raise IndexError, "Cannot find BnfItem of key #{Gdsii::grt_name(key)} in BNF"
  end
end

#eachObject Also known as: each_item

Loops through each BnfItem in this BnfSpec yielding the BnfItem along the way.

spec.each {|bnf_item| ...}


85
86
87
# File 'lib/gdsii/bnf.rb', line 85

def each()
  @bnf_items.each {|bnf_item| yield bnf_item}
end

#find_item(key) ⇒ Object

Finds a BnfItem of a given key in this Bnf object or nil if one is not found.

spec = ...
spec.find_item(GRT_PROPATTR)  #=> BnfItem ...
spec.find_item(GRT_HEADER)    #=> nil


98
99
100
# File 'lib/gdsii/bnf.rb', line 98

def find_item(key)
  @bnf_items.find {|bnf_item| bnf_item.key == key}
end

#inspectObject

Format for inspection



121
122
123
# File 'lib/gdsii/bnf.rb', line 121

def inspect() # :nodoc:
  "#<#{self.class}:0x#{sprintf("%x", self.object_id*2)}:@bnf_items.map {|i| i.to_s}.inspect>"
end