+#######################################################################
+# CLASS QuizAnswer
+# Abstract an answer to a quiz question, by providing self as a string
+# and a core that can be answered as an alternative. It also provides
+# a boolean that tells if the core is numeric or not
+#######################################################################
+class QuizAnswer
+ attr_writer :info
+
+ def initialize(str)
+ @string = str.strip
+ @core = nil
+ if @string =~ /#(.+)#/
+ @core = $1
+ @string.gsub!('#', '')
+ end
+ raise ArgumentError, "empty string can't be a valid answer!" if @string.empty?
+ raise ArgumentError, "empty core can't be a valid answer!" if @core and @core.empty?
+
+ @numeric = (core.to_i.to_s == core) || (core.to_f.to_s == core)
+ @info = nil
+ end
+
+ def core
+ @core || @string
+ end
+
+ def numeric?
+ @numeric
+ end
+
+ def valid?(str)
+ str.downcase == core.downcase || str.downcase == @string.downcase
+ end
+
+ def to_str
+ [@string, @info].join
+ end
+ alias :to_s :to_str
+
+
+end
+
+