Class: DataMetaDom::Mapping
- Inherits:
-
VerDoccable
- Object
- Documentable
- VerDoccable
- DataMetaDom::Mapping
- Defined in:
- lib/dataMetaDom/record.rb
Overview
A mapping - of values from one data type to values of another data types. Supports only DataMeta DOM standard types
For command line details either check the new method’s source or the README.rdoc file, the usage section.
Constant Summary collapse
- BINDING_NONE =
Empty binding for evaluation to avoid exposing class variables
DataMetaXtra.nilBinding
Instance Attribute Summary collapse
-
#base ⇒ Object
The hash of the “from” (source) values to the “to” (target) values.
-
#fromT ⇒ Object
DataType “from” (source).
-
#name ⇒ Object
Name of this mapping data type including namespace if any.
-
#toT ⇒ Object
DataType “to” (target).
Attributes inherited from VerDoccable
Attributes inherited from Documentable
Instance Method Summary collapse
-
#[](key) ⇒ Object
Returns the value for the given key as mapped.
-
#[]=(key, val) ⇒ Object
Assign the mapped value for the given key, useful for building a mapping from the code.
-
#initialize(name) ⇒ Mapping
constructor
Creates an instance for the given full data type name, including namespace if any.
-
#keys ⇒ Object
All the keys of the type “from” (source) defined on the mapping, sorted.
-
#parseBase(source) ⇒ Object
Parses the mapping, the keys and the values from the given source.
-
#values ⇒ Object
All the values of the type “to” (target) defined on the mapping, sorted.
Methods inherited from VerDoccable
Methods inherited from Documentable
#addDoc, #all, #clear, #docConsumed?, #getDoc, #has?, #ids
Constructor Details
#initialize(name) ⇒ Mapping
Creates an instance for the given full data type name, including namespace if any.
38 39 40 41 42 |
# File 'lib/dataMetaDom/record.rb', line 38 def initialize(name) #noinspection RubyArgCount super() @name = name.to_sym; @base = {} end |
Instance Attribute Details
#base ⇒ Object
The hash of the “from” (source) values to the “to” (target) values.
33 34 35 |
# File 'lib/dataMetaDom/record.rb', line 33 def base @base end |
#fromT ⇒ Object
DataType “from” (source)
24 25 26 |
# File 'lib/dataMetaDom/record.rb', line 24 def fromT @fromT end |
#name ⇒ Object
Name of this mapping data type including namespace if any.
20 21 22 |
# File 'lib/dataMetaDom/record.rb', line 20 def name @name end |
#toT ⇒ Object
DataType “to” (target)
28 29 30 |
# File 'lib/dataMetaDom/record.rb', line 28 def toT @toT end |
Instance Method Details
#[](key) ⇒ Object
Returns the value for the given key as mapped.
-
Parameters:
-
key
- the value of the type “from” (source) to get the matching value of the type “to” (target) for.
-
49 |
# File 'lib/dataMetaDom/record.rb', line 49 def [](key); @base[key] end |
#[]=(key, val) ⇒ Object
Assign the mapped value for the given key, useful for building a mapping from the code.
-
Parameters:
-
key
- the value of the type “from” (source) -
val
- the matching value of the type “to” (target).
-
57 |
# File 'lib/dataMetaDom/record.rb', line 57 def []=(key, val); base[key] = val end |
#keys ⇒ Object
All the keys of the type “from” (source) defined on the mapping, sorted
67 |
# File 'lib/dataMetaDom/record.rb', line 67 def keys; @base.keys.sort end |
#parseBase(source) ⇒ Object
Parses the mapping, the keys and the values from the given source.
-
Parameters
-
source
- an instance of SourceFile
-
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/dataMetaDom/record.rb', line 74 def parseBase(source) hashSource = '{' while (line = source.nextLine) case line when /^\s*#{END_KW}\s*$/ self.ver = source.ver unless self.ver self.docs = source.docs.clone source.docs.clear raise "Version missing for the Mapping #{name}" unless self.ver break else hashSource << line end # case end # while line @base = eval(hashSource + '}', BINDING_NONE) self end |
#values ⇒ Object
All the values of the type “to” (target) defined on the mapping, sorted
62 |
# File 'lib/dataMetaDom/record.rb', line 62 def values; @base.values.sort end |