Class: DataMetaDom::RecAttr

Inherits:
Object
  • Object
show all
Defined in:
lib/dataMetaDom/recAttr.rb

Overview

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.

Direct Known Subclasses

RecAttrList, RecAttrSet

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argsObject (readonly)

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.



30
31
32
# File 'lib/dataMetaDom/recAttr.rb', line 30

def args
  @args
end

#hintsObject (readonly)

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



24
25
26
# File 'lib/dataMetaDom/recAttr.rb', line 24

def hints
  @hints
end

#keyObject (readonly)

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



36
37
38
# File 'lib/dataMetaDom/recAttr.rb', line 36

def key
  @key
end

#keywordObject (readonly)

The keyword for the attribute.



19
20
21
# File 'lib/dataMetaDom/recAttr.rb', line 19

def keyword
  @keyword
end

Instance Method Details

#[](index) ⇒ Object

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



91
# File 'lib/dataMetaDom/recAttr.rb', line 91

def [](index); @args[index] end

#addArg(val) ⇒ Object

Adds the given argument, updates the key



57
58
59
60
61
# File 'lib/dataMetaDom/recAttr.rb', line 57

def addArg(val)
    @args << val.to_sym
    updateKey
    self
end

#addArgs(vals) ⇒ Object

Adds an array of arguments.



71
# File 'lib/dataMetaDom/recAttr.rb', line 71

def addArgs(vals); vals.each { |v| addArg v }; self end

#addHint(val) ⇒ Object

Adds the given hint.



66
# File 'lib/dataMetaDom/recAttr.rb', line 66

def addHint(val); @hints << val end

#addHints(vals) ⇒ Object

Adds a collection of hints.



76
# File 'lib/dataMetaDom/recAttr.rb', line 76

def addHints(vals); vals.each { |h| addHint h }; self end

#hasHint?(hint) ⇒ Boolean

Determines if this attribute has the given hint.

Returns:

  • (Boolean)


41
42
43
# File 'lib/dataMetaDom/recAttr.rb', line 41

def hasHint?(hint)
    @hints.member?(hint)
end

#join(delimiter) ⇒ Object

Joins the arguments with the given delimiter.



97
# File 'lib/dataMetaDom/recAttr.rb', line 97

def join(delimiter); @args.join(delimiter) end

#lengthObject

Returns the count of arguments.



86
# File 'lib/dataMetaDom/recAttr.rb', line 86

def length; @args.length end

#parse(source) ⇒ Object

Parses this instance from the given source.

  • Parameter:

    • source - an instance of SourceFile



104
105
106
107
108
109
110
111
112
113
114
115
116
117
# 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_sObject

textual representation of this instance



120
# File 'lib/dataMetaDom/recAttr.rb', line 120

def to_s; "#@keyword:#@key; #@sourceRef" end

#updateKeyObject

Updates the key, returns self for call chaining



81
# File 'lib/dataMetaDom/recAttr.rb', line 81

def updateKey; @key = getKey; self end