Class: Opencdd::DataType
- Inherits:
-
Object
show all
- Defined in:
- lib/opencdd/data_type.rb
Defined Under Namespace
Classes: ClassReference, EnumReferenceType, EnumStringType, IntegerMeasureType, RealMeasureType
Constant Summary
collapse
- SIMPLE =
%w[
STRING_TYPE TRANSLATABLE_STRING_TYPE REAL_TYPE INTEGER_TYPE INT_TYPE
BOOLEAN_TYPE DATE_TYPE DATE_TIME_TYPE DATETIME_TYPE TIME_TYPE
IRDI_TYPE ICID_STRING ICID_STRING_TYPE URL_TYPE MIME_TYPE FILE_TYPE
COMPLEX_TYPE
].freeze
- MEASURE =
%w[REAL_MEASURE_TYPE INTEGER_MEASURE_TYPE INT_MEASURE_TYPE].freeze
- PARAMETERIZED =
%w[CLASS_REFERENCE ENUM_STRING_TYPE ENUM_REFERENCE_TYPE].freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(kind) ⇒ DataType
Returns a new instance of DataType.
18
19
20
|
# File 'lib/opencdd/data_type.rb', line 18
def initialize(kind)
@kind = kind.to_s
end
|
Instance Attribute Details
#kind ⇒ Object
Returns the value of attribute kind.
16
17
18
|
# File 'lib/opencdd/data_type.rb', line 16
def kind
@kind
end
|
Class Method Details
.parse(raw) ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/opencdd/data_type.rb', line 110
def parse(raw)
return nil if raw.nil? || raw.to_s.strip.empty?
s = raw.to_s.strip
if s =~ /\ACLASS_REFERENCE\s*\(\s*(.+?)\s*\)\z/
return ClassReference.new(Regexp.last_match(1))
end
if s =~ /\AENUM_STRING_TYPE\s*\(\s*(.+?)\s*\)\z/
return EnumStringType.new(Regexp.last_match(1))
end
if s =~ /\AENUM_REFERENCE_TYPE\s*\(\s*(.+?)\s*\)\z/
return EnumReferenceType.new(Regexp.last_match(1))
end
case s
when "REAL_MEASURE_TYPE", "REAL_MEASURE"
RealMeasureType.new
when "INTEGER_MEASURE_TYPE", "INT_MEASURE_TYPE", "INTEGER_MEASURE", "INT_MEASURE"
IntegerMeasureType.new
when *SIMPLE
new(s)
else
raise ArgumentError, "unknown data_type: #{s.inspect}"
end
end
|
.parse_or_string(raw) ⇒ Object
136
137
138
139
140
|
# File 'lib/opencdd/data_type.rb', line 136
def parse_or_string(raw)
parse(raw)
rescue ArgumentError
raw.to_s
end
|
Instance Method Details
#==(other) ⇒ Object
Also known as:
eql?
34
35
36
|
# File 'lib/opencdd/data_type.rb', line 34
def ==(other)
other.is_a?(Opencdd::DataType) && to_s == other.to_s
end
|
#class_reference? ⇒ Boolean
31
|
# File 'lib/opencdd/data_type.rb', line 31
def class_reference? = false
|
#enum? ⇒ Boolean
32
|
# File 'lib/opencdd/data_type.rb', line 32
def enum? = false
|
#hash ⇒ Object
39
40
41
|
# File 'lib/opencdd/data_type.rb', line 39
def hash
to_s.hash
end
|
#measure? ⇒ Boolean
23
24
25
26
|
# File 'lib/opencdd/data_type.rb', line 23
def measure? = MEASURE.include?(@kind)
|
#parameterized? ⇒ Boolean
29
|
# File 'lib/opencdd/data_type.rb', line 29
def parameterized? = PARAMETERIZED.include?(@kind)
|
#reference? ⇒ Boolean
Base default — overridden by reference-carrying subclasses.
Replaces the previous is_a? chain across ClassReference /
EnumStringType / EnumReferenceType with per-subclass override.
27
|
# File 'lib/opencdd/data_type.rb', line 27
def reference? = false
|
#simple? ⇒ Boolean
22
|
# File 'lib/opencdd/data_type.rb', line 22
def simple? = SIMPLE.include?(@kind)
|
#to_s ⇒ Object
Also known as:
inspect
43
44
45
|
# File 'lib/opencdd/data_type.rb', line 43
def to_s
@kind
end
|