Class: Gdsii::RecData::Int2

Inherits:
Data
  • Object
show all
Defined in:
lib/gdsii/record/datatypes/int2.rb

Overview

Store a GDSII INT2 data type

Instance Attribute Summary collapse

Attributes inherited from Data

#record, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Data

#[], #is_ascii?, #is_bitarray?, #is_int2?, #is_int4?, #is_no_data?, #is_real4?, #is_real8?, valid_type?

Constructor Details

#initialize(value) ⇒ Int2

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



18
19
20
# File 'lib/gdsii/record/datatypes/int2.rb', line 18

def initialize(value)
  super(GDT_INT2, value)
end

Instance Attribute Details

#valueObject

Value is an array of integers.



14
15
16
# File 'lib/gdsii/record/datatypes/int2.rb', line 14

def value
  @value
end

Class Method Details

.read(file, byte_count) ⇒ Object

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



36
37
38
39
40
41
42
43
44
45
# 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

Instance Method Details

#byte_sizeObject

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



30
31
32
# File 'lib/gdsii/record/datatypes/int2.rb', line 30

def byte_size()
  @value.length * 2
end

#to_sObject

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



58
59
60
# File 'lib/gdsii/record/datatypes/int2.rb', line 58

def to_s()
  value.map {|v| v.to_s}.join(' ')
end

#write(file) ⇒ Object

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



49
50
51
52
53
54
# 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