Class: DataMetaDom::DataType
- Inherits:
-
Object
- Object
- DataMetaDom::DataType
- Defined in:
- lib/dataMetaDom/dataType.rb
Overview
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.
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
For those data types that have a dimension, such as length.
-
#scale ⇒ Object
readonly
For those data types that have a scale.
-
#type ⇒ Object
Base type; either one of the standard types, see STANDARD_TYPES on the util.rb or fully named custom type such as a Record, an Enum, a Map, a BitSet.
Class Method Summary collapse
-
.canDim(type) ⇒ Object
The type may or may not feature a length.
-
.mustDim(type) ⇒ Object
The type must feature a length > 0.
-
.mustNotDim(type) ⇒ Object
The type must not feature a length.
-
.parse(src, textual) ⇒ Object
Parses type definition from DataMeta DOM source, raising errors if anything is wrong.
Instance Method Summary collapse
-
#initialize(t, len = nil, scale = nil) ⇒ DataType
constructor
Creates the instance with the given base type, the length and the scale.
-
#length_spec ⇒ Object
Builds a length (dimension) and scale specification for this type according to the DataMeta DOM syntax.
-
#to_s ⇒ Object
Textual representation of this isntance, includes the type spec with the length spec.
Constructor Details
#initialize(t, len = nil, scale = nil) ⇒ DataType
Creates the instance with the given base type, the length and the scale
74 75 76 77 78 79 80 81 82 83 |
# 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 |
Instance Attribute Details
#length ⇒ Object (readonly)
For those data types that have a dimension, such as length. See DIMMED_TYPES on the util.rb.
25 26 27 |
# File 'lib/dataMetaDom/dataType.rb', line 25 def length @length end |
#scale ⇒ Object (readonly)
For those data types that have a scale. See SCALE_TYPES on the util.rb.
30 31 32 |
# File 'lib/dataMetaDom/dataType.rb', line 30 def scale @scale end |
#type ⇒ Object
Base type; either one of the standard types, see STANDARD_TYPES on the util.rb or fully named custom type such as a Record, an Enum, a Map, a BitSet.
Use case of changing the type: multiple versions in one VM process.
20 21 22 |
# File 'lib/dataMetaDom/dataType.rb', line 20 def type @type end |
Class Method Details
.canDim(type) ⇒ Object
The type may or may not feature a length
44 45 46 |
# File 'lib/dataMetaDom/dataType.rb', line 44 def canDim(type) DIMMED_TYPES.member?(type) || OPT_DIMMABLE.member?(type) end |
.mustDim(type) ⇒ Object
The type must feature a length > 0
39 40 41 |
# File 'lib/dataMetaDom/dataType.rb', line 39 def mustDim(type) DIMMED_TYPES.member?(type) end |
.mustNotDim(type) ⇒ Object
The type must not feature a length
34 35 36 |
# File 'lib/dataMetaDom/dataType.rb', line 34 def mustNotDim(type) !DIMMED_TYPES.member?(type) && !OPT_DIMMABLE.member?(type) end |
.parse(src, textual) ⇒ Object
Parses type definition from DataMeta DOM source, raising errors if anything is wrong. Returns a new instance of the DataType.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# 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 |
Instance Method Details
#length_spec ⇒ Object
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.
89 |
# File 'lib/dataMetaDom/dataType.rb', line 89 def length_spec; @length && @length != 0 ? "[#{@length}" + (@scale ? '.' + @scale.to_s : '') + ']' : '' end |
#to_s ⇒ Object
Textual representation of this isntance, includes the type spec with the length spec.
92 |
# File 'lib/dataMetaDom/dataType.rb', line 92 def to_s; "#{@type}#{length_spec}" end |