module VORuby module VOTables module VOTable # Miscellaneous classes that don't fit elsewhere. module Misc # An exception thrown when the incoming type does not match # the expected value. class TypeException < Exception # [_obj_:] # The object itself. # [_prototype_:] # The prototype of the expected class. def initialize(obj=nil, prototype=nil) super("Invalid type: #{obj.class} (#{obj}) != #{prototype}") end end # A class which checks to see whether the type of the incoming class # matches expectation. class TypeCheck attr_accessor :obj, :proto # [_obj_:] # The object in question. # [_proto_:] # The prototype of the expected class. def initialize(obj=nil, proto=nil) #raise "TypeCheck must have an object" if obj == nil #raise "TypeCheck must have a prototype" if proto == nil @obj = obj @proto = proto end # Check to see whether the class is of the expected type. def check raise TypeException.new(@obj, @proto) if @obj and !@obj.is_a?(@proto) end def to_s "{object=#{@obj};prototype=#{@proto}}" end end end end end end