class MODL::Parser::MODLClass

Represents a *class defined, or loaded by, a MODL document.

Attributes

allow[RW]
assign[RW]
content[RW]
expect[RW]
id[RW]
name[RW]
superclass[RW]

Public Class Methods

new() click to toggle source
# File lib/modl/parser/modl_class.rb, line 37
def initialize
  @content = {}
end

Public Instance Methods

keylist_of_length(len) click to toggle source

Find a keylist of the right length from the *assign array of arrays.

# File lib/modl/parser/modl_class.rb, line 42
def keylist_of_length(len)
  return nil if @assign.nil?

  # *assign can support iteration, e.g. *assign=[[person*]]
  # so return a list of the right length in this case
  if @assign.length == 1 && @assign[0].length == 1 && @assign[0][0].end_with?('*')
    key = Sutil.head @assign[0][0]
    return Array.new(len, key)
  end

  @assign.each do |kl|
    return kl if kl.length == len
  end

  raise InterpreterError,
        'Interpreter Error: No key list of the correct length in class ' + @id + ' - looking for one of length ' + len.to_s
end
merge_content(new_value) click to toggle source
# File lib/modl/parser/modl_class.rb, line 60
def merge_content(new_value)
  @content.each do |k, v|
    new_value[k] = v.extract_hash unless new_value[k]
  end
  new_value
end
name_or_id() click to toggle source
# File lib/modl/parser/modl_class.rb, line 67
def name_or_id
  @name.nil? ? @id : @name
end