class Gdsii::RecData::Data

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

Attributes

record[R]

Pointer to the parent record object

type[R]

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

Public Class Methods

new(type, value, record=nil) click to toggle source

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

# 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
valid_type?(type) click to toggle source

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

# File lib/gdsii/record/datatypes/data.rb, line 38
def Data.valid_type?(type)
  (0...DATATYPE_INFO.length).member?(type)
end

Protected Class Methods

coerce_value(value, klass, coerce_method) click to toggle source

Generic method for setting a value. The classes that inherit from this class use this to coerce and validate their value.

# File lib/gdsii/record/datatypes/data.rb, line 94
def Data.coerce_value(value, klass, coerce_method)
  Data.ensure_array value
  value.each_with_index do |datum, i|
    # Make sure that it matches the class; if not, try to coerce
    unless datum.kind_of?(klass) 
      if datum.respond_to?(coerce_method) then
        the_method = datum.method(coerce_method)
        value[i] = the_method.call
      end
      Data.ensure_class(value[i], klass)
    end
  end
  value
end
ensure_array(value) click to toggle source

Ensures that the given value is descended from the Array class. If not, then an InvalidValue exception is raised.

# File lib/gdsii/record/datatypes/data.rb, line 85
def Data.ensure_array(value)
  unless value.kind_of?(Array)
    raise TypeError,
    "All data must be descended from Array class; given: #{value.class}"
  end
end
ensure_class(datum, klass) click to toggle source

Check the class for the given datum (single data element, NOT an array) and raises an exception if the datum does not match the given class.

# File lib/gdsii/record/datatypes/data.rb, line 76
def Data.ensure_class(datum, klass)
  unless datum.kind_of?(klass)
    raise TypeError,
    "#{self.class.to_s} value must be descended from #{klass}; given: '#{datum.class}'"
  end
end

Public Instance Methods

[](index) click to toggle source

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

# File lib/gdsii/record/datatypes/data.rb, line 34
def [](index); @value[index]; end
is_ascii?() click to toggle source

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

# File lib/gdsii/record/datatypes/data.rb, line 47
def is_ascii?(); @type == GDT_ASCII; end
is_bitarray?() click to toggle source

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

# File lib/gdsii/record/datatypes/data.rb, line 59
def is_bitarray?(); @type == GDT_BITARRAY; end
is_int2?() click to toggle source

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

# File lib/gdsii/record/datatypes/data.rb, line 50
def is_int2?(); @type == GDT_INT2; end
is_int4?() click to toggle source

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

# File lib/gdsii/record/datatypes/data.rb, line 53
def is_int4?(); @type == GDT_INT4; end
is_no_data?() click to toggle source

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

# File lib/gdsii/record/datatypes/data.rb, line 62
def is_no_data?(); @type == GDT_NO_DATA; end
is_real4?() click to toggle source

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

# File lib/gdsii/record/datatypes/data.rb, line 65
def is_real4?(); @type == GDT_REAL4; end
is_real8?() click to toggle source

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

# File lib/gdsii/record/datatypes/data.rb, line 56
def is_real8?(); @type == GDT_REAL8; end