class DataMetaDom::DataType
DataMeta DOM Data Type, including the base type, length if any and scale if any.
For command line details either check the new method's source or the README.rdoc file, the usage section.
Attributes
For those data types that have a dimension, such as length. See DIMMED_TYPES on the util.rb.
For those data types that have a scale. See SCALE_TYPES on the util.rb.
Public Class Methods
The type may or may not feature a length
# File lib/dataMetaDom/dataType.rb, line 44 def canDim(type) DIMMED_TYPES.member?(type) || OPT_DIMMABLE.member?(type) end
The type must feature a length > 0
# File lib/dataMetaDom/dataType.rb, line 39 def mustDim(type) DIMMED_TYPES.member?(type) end
The type must not feature a length
# File lib/dataMetaDom/dataType.rb, line 34 def mustNotDim(type) !DIMMED_TYPES.member?(type) && !OPT_DIMMABLE.member?(type) end
Creates the instance with the given base type, the length and the scale
# File lib/dataMetaDom/dataType.rb, line 74 def initialize(t, len=nil, scale=nil) raise ArgumentError, "The type #{t} can not have length" if DataType.mustNotDim(t) && len raise ArgumentError, "The type #{type} must have length > 0, but \"#{len}\" specified" \ if DataType.mustDim(t) && (!len || len < 1) @type = t.to_sym @length = len @scale = scale end
Parses type definition from DataMeta DOM source, raising errors if anything is wrong. Returns a new instance of the DataType
.
# File lib/dataMetaDom/dataType.rb, line 52 def parse(src, textual) r = textual.scan(/([\w\.]+)(\[[\d\.]+\])?/) raise "Invalid data type spec #{textual}" unless r typeSpec, dimSpec = r[0] type = typeSpec.to_sym raise "The type #{type} can not be dimensioned" if DataType.mustNotDim(type) && dimSpec && !dimSpec.empty? raise "The type #{type} must be dimensioned" if DataType.mustDim(type) && (!dimSpec || dimSpec.empty?) length = nil; scale = nil unless !dimSpec || dimSpec.empty? raise "Invalid dimension format '#{dimSpec}'" unless dimSpec.scan(/^\[(\d+)\.?(\d+)?\]$/) length = $1.to_i scale = $2 ? $2.to_i : nil end @type = DataMetaDom.fullTypeName(src.namespace, type) DataType.new @type, length, scale end
Public Instance Methods
Builds a length (dimension) and scale specification for this type according to the DataMeta DOM syntax. If the type does not have a dimension (no length, no scale), returns empty string.
# File lib/dataMetaDom/dataType.rb, line 89 def length_spec; @length && @length != 0 ? "[#{@length}" + (@scale ? '.' + @scale.to_s : '') + ']' : '' end
Textual representation of this isntance, includes the type spec with the length spec.
# File lib/dataMetaDom/dataType.rb, line 92 def to_s; "#{@type}#{length_spec}" end