Parent

Class/Module Index [+]

Quicksearch

RGen::MetamodelBuilder::DataTypes::Enum

An enum object is used to describe possible attribute values within a MetamodelBuilder attribute definition. An attribute defined this way can only take the values specified when creating the Enum object. Literal values can only be symbols or true or false. Optionally a name may be specified for the enum object.

Examples:

Enum.new(:name => "AnimalEnum", :literals => [:cat, :dog])
Enum.new(:literals => [:cat, :dog])
Enum.new([:cat, :dog])

Attributes

literals[R]
name[R]

Public Class Methods

new(params) click to toggle source

Creates a new named enum type object consisting of the elements passed as arguments.

# File lib/rgen/metamodel_builder/data_types.rb, line 23
    def initialize(params)
MetamodelBuilder::ConstantOrderHelper.enumCreated(self)
         if params.is_a?(Array)
              @literals = params
                 @name = "anonymous"
         elsif params.is_a?(Hash)
                 raise StandardError.new("Hash entry :literals is missing") unless params[:literals]
                 @literals = params[:literals]
                 @name = params[:name] || "anonymous"
         else
                 raise StandardError.new("Pass an Array or a Hash")
         end
    end

Public Instance Methods

literals_as_strings() click to toggle source
# File lib/rgen/metamodel_builder/data_types.rb, line 43
def literals_as_strings
     literals.collect do |l|
             if l.is_a?(Symbol)
if l.to_s =~ /^\d|\W/
  ":'"+l.to_s+"'"
else
  ":"+l.to_s
end
             elsif l.is_a?(TrueClass) || l.is_a?(FalseClass)
                     l.to_s
             else
                     raise StandardError.new("Literal values can only be symbols or true/false")
             end
     end
end
validLiteral?(l) click to toggle source

This method can be used to check if an object can be used as value for variables having this enum object as type.

# File lib/rgen/metamodel_builder/data_types.rb, line 39
def validLiteral?(l)
  literals.include?(l)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.