class DataMetaDom::RecAttr
Record
Attribute such as unique fields set, identity information, indexes, references etc the common structure is like this: keyword (hint1, hint2, hint3…) arg1, arg2
For command line details either check the new method's source or the README.rdoc file, the usage section.
Attributes
Arguments on this attribute if any, an array in the order as listed in the DataMeta DOM source. Order is important, for example, for an identity.
A Set of hints, empty set if there are no hints on this attribute.
Unique key for the given attribute to distinguish between those and use in a map. Rebuilt by getKey method defined on the subclasses.
The keyword for the attribute.
Public Class Methods
Creates an instance for the given keyword.
# File lib/dataMetaDom/recAttr.rb, line 48 def initialize(keyword) @keyword = keyword.to_sym raise "Unsupported keyword #@keyword" unless REC_ATTR_KEYWORDS.member?(@keyword) @args = []; @hints = Set.new end
Public Instance Methods
Returns the arguments in the given position, zero-based.
# File lib/dataMetaDom/recAttr.rb, line 91 def [](index); @args[index] end
Adds the given argument, updates the key
# File lib/dataMetaDom/recAttr.rb, line 57 def addArg(val) @args << val.to_sym updateKey self end
Adds an array of arguments.
# File lib/dataMetaDom/recAttr.rb, line 71 def addArgs(vals); vals.each { |v| addArg v }; self end
Adds the given hint.
# File lib/dataMetaDom/recAttr.rb, line 66 def addHint(val); @hints << val end
Adds a collection of hints.
# File lib/dataMetaDom/recAttr.rb, line 76 def addHints(vals); vals.each { |h| addHint h }; self end
Determines if this attribute has the given hint.
# File lib/dataMetaDom/recAttr.rb, line 41 def hasHint?(hint) @hints.member?(hint) end
Joins the arguments with the given delimiter.
# File lib/dataMetaDom/recAttr.rb, line 97 def join(delimiter); @args.join(delimiter) end
Returns the count of arguments.
# File lib/dataMetaDom/recAttr.rb, line 86 def length; @args.length end
Parses this instance from the given source.
-
Parameter:
-
source
- an instance ofSourceFile
-
# File lib/dataMetaDom/recAttr.rb, line 104 def parse(source) @sourceRef = source.snapshot line = source.line recAttrMatch = line.scan(/^\s*(\w*)\s*(\([^\)]+\))?\s+(.+)$/) raise "Invalid record attribute spec '#{line}'" unless recAttrMatch keyw, hintList, argList = recAttrMatch[0] raise "Wrong keyword '#{keyw}', '#@keyword' expected instead" unless keyw && keyw.to_sym == @keyword @args = argList.split(/[\(\)\s\,]+/).map { |a| a.to_sym } if hintList @hints = Set.new hintList.split(/[\(\)\s\,]+/).select { |h| !h.strip.empty? }.map { |h| h.strip.to_sym } else @hints = Set.new end end
textual representation of this instance
# File lib/dataMetaDom/recAttr.rb, line 120 def to_s; "#@keyword:#@key; #@sourceRef" end
Updates the key, returns self for call chaining
# File lib/dataMetaDom/recAttr.rb, line 81 def updateKey; @key = getKey; self end