Class: WAB::Data
- Inherits:
-
Object
- Object
- WAB::Data
- Defined in:
- lib/wab/data.rb
Overview
The class representing the cananical data structure in WAB. Typically the Data instances are factory created by the Shell and will most likely not be instance of this class but rather a class that is a duck-type of this class (has the same methods and behavior).
Direct Known Subclasses
Instance Method Summary collapse
-
#deep_dup ⇒ Object
Make a deep copy of the Data instance.
-
#detect ⇒ Object
- Detects and converts strings to Ruby objects following the rules: Time
- “2017-01-05T15:04:33.123456789Z”, zulu only UUID
- “b0ca922d-372e-41f4-8fea-47d880188ba3” URI
-
“opo.technology/sample”, HTTP only.
-
#each ⇒ Object
Each child of the Data instance is provided as an argument to a block when the each method is called.
-
#each_leaf ⇒ Object
Each leaf of the Data instance is provided as an argument to a block when the each method is called.
-
#get(_path) ⇒ Object
Gets the Data element or value identified by the path where the path elements are separated by the ‘.’ character.
-
#has?(_path) ⇒ Boolean
Returns true if the Data element or value identified by the path exists where the path elements are separated by the ‘.’ character.
-
#json(_indent = 0) ⇒ Object
Encode the data as a JSON string.
-
#native ⇒ Object
Returns the instance converted to native Ruby values such as a Hash, Array, etc.
-
#set(_path, _value) ⇒ Object
Sets the node value identified by the path where the path elements are separated by the ‘.’ character.
Instance Method Details
#deep_dup ⇒ Object
Make a deep copy of the Data instance.
60 61 62 |
# File 'lib/wab/data.rb', line 60 def deep_dup() raise NotImplementedError.new end |
#detect ⇒ Object
Detects and converts strings to Ruby objects following the rules:
- Time
-
“2017-01-05T15:04:33.123456789Z”, zulu only
- UUID
-
“b0ca922d-372e-41f4-8fea-47d880188ba3”
- URI
-
“opo.technology/sample”, HTTP only
79 80 81 |
# File 'lib/wab/data.rb', line 79 def detect() raise NotImplementedError.new end |
#each ⇒ Object
Each child of the Data instance is provided as an argument to a block when the each method is called.
47 48 49 |
# File 'lib/wab/data.rb', line 47 def each() raise NotImplementedError.new end |
#each_leaf ⇒ Object
Each leaf of the Data instance is provided as an argument to a block when the each method is called. A leaf is a primitive that has no children and will be nil, a Boolean, String, Numberic, Time, WAB::UUID, or URI.
55 56 57 |
# File 'lib/wab/data.rb', line 55 def each_leaf() raise NotImplementedError.new end |
#get(_path) ⇒ Object
Gets the Data element or value identified by the path where the path elements are separated by the ‘.’ character. The path can also be a array of path node identifiers. For example, child.grandchild is the same as [‘child’, ‘grandchild’].
24 25 26 |
# File 'lib/wab/data.rb', line 24 def get(_path) raise NotImplementedError.new end |
#has?(_path) ⇒ Boolean
Returns true if the Data element or value identified by the path exists where the path elements are separated by the ‘.’ character. The path can also be a array of path node identifiers. For example, child.grandchild is the same as [‘child’, ‘grandchild’].
16 17 18 |
# File 'lib/wab/data.rb', line 16 def has?(_path) raise NotImplementedError.new end |
#json(_indent = 0) ⇒ Object
Encode the data as a JSON string.
71 72 73 |
# File 'lib/wab/data.rb', line 71 def json(_indent=0) raise NotImplementedError.new end |
#native ⇒ Object
Returns the instance converted to native Ruby values such as a Hash, Array, etc.
66 67 68 |
# File 'lib/wab/data.rb', line 66 def native() raise NotImplementedError.new end |
#set(_path, _value) ⇒ Object
Sets the node value identified by the path where the path elements are separated by the ‘.’ character. The path can also be a array of path node identifiers. For example, child.grandchild is the same as [‘child’, ‘grandchild’]. The value must be one of the allowed data values described in the initialize method.
For arrays, the behavior is similar to an Array#[] with the exception of a negative index less than the negative length in which case the value is prepended (Array#unshift).
- path
-
path to location to be set
- value
-
value to set
- repair
-
flag indicating invalid value should be repaired if possible
41 42 43 |
# File 'lib/wab/data.rb', line 41 def set(_path, _value) raise NotImplementedError.new end |