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

args[R]

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.

hints[R]

A Set of hints, empty set if there are no hints on this attribute.

key[R]

Unique key for the given attribute to distinguish between those and use in a map. Rebuilt by getKey method defined on the subclasses.

keyword[R]

The keyword for the attribute.

Public Class Methods

new(keyword) click to toggle source

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

[](index) click to toggle source

Returns the arguments in the given position, zero-based.

# File lib/dataMetaDom/recAttr.rb, line 91
def [](index); @args[index] end
addArg(val) click to toggle source

Adds the given argument, updates the key

# File lib/dataMetaDom/recAttr.rb, line 57
def addArg(val)
    @args << val.to_sym
    updateKey
    self
end
addArgs(vals) click to toggle source

Adds an array of arguments.

# File lib/dataMetaDom/recAttr.rb, line 71
def addArgs(vals); vals.each { |v| addArg v }; self end
addHint(val) click to toggle source

Adds the given hint.

# File lib/dataMetaDom/recAttr.rb, line 66
def addHint(val); @hints << val end
addHints(vals) click to toggle source

Adds a collection of hints.

# File lib/dataMetaDom/recAttr.rb, line 76
def addHints(vals); vals.each { |h| addHint h }; self end
hasHint?(hint) click to toggle source

Determines if this attribute has the given hint.

# File lib/dataMetaDom/recAttr.rb, line 41
def hasHint?(hint)
    @hints.member?(hint)
end
join(delimiter) click to toggle source

Joins the arguments with the given delimiter.

# File lib/dataMetaDom/recAttr.rb, line 97
def join(delimiter); @args.join(delimiter) end
length() click to toggle source

Returns the count of arguments.

# File lib/dataMetaDom/recAttr.rb, line 86
def length; @args.length end
parse(source) click to toggle source

Parses this instance from the given source.

# 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
to_s() click to toggle source

textual representation of this instance

# File lib/dataMetaDom/recAttr.rb, line 120
def to_s; "#@keyword:#@key; #@sourceRef" end
updateKey() click to toggle source

Updates the key, returns self for call chaining

# File lib/dataMetaDom/recAttr.rb, line 81
def updateKey; @key = getKey; self end