class Gdsii::RecData::Int2

Store a GDSII INT2 data type

Attributes

value[R]

Value is an array of integers.

Public Class Methods

new(value) click to toggle source

Construct an Gdsii::RecData::Int2 data object. The value is an array of integers (Fixnum).

Calls superclass method Gdsii::RecData::Data.new
# File lib/gdsii/record/datatypes/int2.rb, line 18
def initialize(value)
  super(GDT_INT2, value)
end
read(file, byte_count) click to toggle source

Reads an INT2 record from the given file and for the length of bytes given and returns a new Gdsii::RecData::Int2 object.

# File lib/gdsii/record/datatypes/int2.rb, line 36
def Int2.read(file, byte_count)
  data = []
  while (byte_count > 0)
    raw = file.read(2)
    raw.reverse! if (ByteOrder::little_endian?)
    data.push raw.unpack('s')[0]
    byte_count -= 2
  end
  Int2.new(data)
end

Public Instance Methods

byte_size() click to toggle source

Returns the size of the record data in bytes. Each array element consumes 2 bytes (hence INT2).

# File lib/gdsii/record/datatypes/int2.rb, line 30
def byte_size()
  @value.length * 2
end
to_s() click to toggle source

Converts the array of integer values to a string (values are joined by spaces).

# File lib/gdsii/record/datatypes/int2.rb, line 58
def to_s()
  value.map {|v| v.to_s}.join(' ')
end
value=(value) click to toggle source

Set the value for this object; verify that the value items are of type Fixnum (or at least can be coerced using “to_i”).

# File lib/gdsii/record/datatypes/int2.rb, line 24
def value=(value)
  @value = Data.coerce_value(value, Fixnum, :to_i)
end
write(file) click to toggle source

Writes the integer values in this Gdsii::RecData::Int2 object to the given file as a GDSII INT2 record.

# File lib/gdsii/record/datatypes/int2.rb, line 49
def write(file)
  value.each do |item|
    # always write int2 as network order (as per GDSII spec)
    file.write [item].pack('n')
  end
end