Class: Gdsii::RecData::Data

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

Overview

Generic class to represent various record data types. This class is intended to be inherited and not called directly.

Direct Known Subclasses

Ascii, BitArray, Int2, Int4, NoData, Real4, Real8

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, value, record = nil) ⇒ Data

Create a generic record data object. Intended to be called internally by Gdsii::RecType classes - not intended to be called directly.



22
23
24
25
26
27
28
29
30
31
# File 'lib/gdsii/record/datatypes/data.rb', line 22

def initialize(type, value, record=nil)
  if Data.valid_type?(type)
    @type = type
  else
    raise TypeError,
    "Invalid data type specified: #{type}"
  end
  @record = record
  self.value = value
end

Instance Attribute Details

#recordObject (readonly)

Pointer to the parent record object



16
17
18
# File 'lib/gdsii/record/datatypes/data.rb', line 16

def record
  @record
end

#typeObject (readonly)

Data type integer represented by one of the Gdsii::GDT_ constants.



13
14
15
# File 'lib/gdsii/record/datatypes/data.rb', line 13

def type
  @type
end

Class Method Details

.valid_type?(type) ⇒ Boolean

Check that the given data type (as an integer) is valid as defined by the Gdsii::DATATYPE_INFO array.

Returns:

  • (Boolean)


38
39
40
# File 'lib/gdsii/record/datatypes/data.rb', line 38

def Data.valid_type?(type)
  (0...DATATYPE_INFO.length).member?(type)
end

Instance Method Details

#[](index) ⇒ Object

Quick access to the data value array. Equivalent to self.value.



34
# File 'lib/gdsii/record/datatypes/data.rb', line 34

def [](index); @value[index]; end

#is_ascii?Boolean

Returns true if this record is an ASCII data type, false if not

Returns:

  • (Boolean)


47
# File 'lib/gdsii/record/datatypes/data.rb', line 47

def is_ascii?(); @type == GDT_ASCII; end

#is_bitarray?Boolean

Returns true if this record is a BITARRAY data type, false if not

Returns:

  • (Boolean)


59
# File 'lib/gdsii/record/datatypes/data.rb', line 59

def is_bitarray?(); @type == GDT_BITARRAY; end

#is_int2?Boolean

Returns true if this record is an INT2 data type, false if not

Returns:

  • (Boolean)


50
# File 'lib/gdsii/record/datatypes/data.rb', line 50

def is_int2?(); @type == GDT_INT2; end

#is_int4?Boolean

Returns true if this record is an INT4 data type, false if not

Returns:

  • (Boolean)


53
# File 'lib/gdsii/record/datatypes/data.rb', line 53

def is_int4?(); @type == GDT_INT4; end

#is_no_data?Boolean

Returns true if this record is a NO_DATA data type, false if not

Returns:

  • (Boolean)


62
# File 'lib/gdsii/record/datatypes/data.rb', line 62

def is_no_data?(); @type == GDT_NO_DATA; end

#is_real4?Boolean

Returns true if this record is a REAL4 data type, false if not

Returns:

  • (Boolean)


65
# File 'lib/gdsii/record/datatypes/data.rb', line 65

def is_real4?(); @type == GDT_REAL4; end

#is_real8?Boolean

Returns true if this record is a REAL8 data type, false if not

Returns:

  • (Boolean)


56
# File 'lib/gdsii/record/datatypes/data.rb', line 56

def is_real8?(); @type == GDT_REAL8; end