Class: Gdsii::BnfSpec
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
-
#bnf_items ⇒ Object
readonly
Returns the value of attribute bnf_items.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Shortcut for #find_item but will raise an exception if the item key is not part of this BNF.
-
#each ⇒ Object
(also: #each_item)
Loops through each BnfItem in this BnfSpec yielding the BnfItem along the way.
-
#find_item(key) ⇒ Object
Finds a BnfItem of a given key in this Bnf object or nil if one is not found.
-
#initialize(*bnf_items) ⇒ BnfSpec
constructor
Creates a Backus-Naur Form (BNF) grouping consisting of BnfItem objects.
-
#inspect ⇒ Object
Format for inspection.
Constructor Details
Instance Attribute Details
#bnf_items ⇒ Object (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 |
#each ⇒ Object 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 |
#inspect ⇒ Object
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 |