Class: DataMetaDom::RecAttrSet

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

Overview

The record attribute with the unordered set of arguments. See the RecAttrList for the ordered list implementation.

Direct Known Subclasses

RecIdentity, RecUnique

Instance Attribute Summary collapse

Attributes inherited from RecAttr

#args, #hints, #key, #keyword

Instance Method Summary collapse

Methods inherited from RecAttr

#[], #addArgs, #addHint, #addHints, #hasHint?, #join, #length, #to_s, #updateKey

Constructor Details

#initialize(keyword) ⇒ RecAttrSet

Creates an instance with the given keyword



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

def initialize(keyword); super(keyword); @argSet = Set.new end

Instance Attribute Details

#argSetObject (readonly)

Unordered unique set of the arguments



132
133
134
# File 'lib/dataMetaDom/recAttr.rb', line 132

def argSet
  @argSet
end

Instance Method Details

#addArg(val) ⇒ Object

Adds the given argument to the instance



150
151
152
153
154
155
156
# File 'lib/dataMetaDom/recAttr.rb', line 150

def addArg(val)
    k = val.to_sym
    raise "Duplicate arg #{k} in the set of #{argSetTextual}" if @argSet.member?(k)
    @argSet << k
    #RecAttr.instance_method(:addArg).bind(self).call k - fortunately, overkill in this case, can do with just:
    super k
end

#argSetTextualObject

Builds textual for the set of the arguments, for diagnostics.



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

def argSetTextual; @argSet.map { |a| a.to_s }.sort.join(':') end

#getKeyObject

Builds the unique key for the set of arguments on the instance



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

def getKey; argSetTextual.to_sym end

#hasArg?(arg) ⇒ Boolean

Determines if the instance has the given argument

Returns:

  • (Boolean)


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

def hasArg?(arg); argSet.member?(arg) end

#parse(src) ⇒ Object

Parses the instance from the given source.

  • Parameters

    • src - an instance of SourceFile



163
164
165
166
167
168
169
170
171
172
173
# File 'lib/dataMetaDom/recAttr.rb', line 163

def parse(src)
    recAttrParse(src)
    # look if there are any duplicates, if there are it's an error:
    counterHash = Hash.new(0)
    args.each { |a| k=a.to_sym; counterHash[k] += 1 }
    dupes = []; counterHash.each { |k, v| dupes << k if v > 1 }
    raise "Duplicate arguments for #{self} - [#{dupes.join(',')}]" unless dupes.empty?
    @argSet = Set.new(args)
    updateKey
    self
end

#recAttrParseObject

Engages the super’s parse method via the alias



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

alias :recAttrParse :parse