package com.tadSrc.tadsClasses
{
public class Checker
{
private var theObject:*;
private var numz:String = "-0123456789";
private var alphaz:String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
private var nocs:String = ")(*&^%$#@!~`:;-'\"?><{}+_[]\|,/.";
public function Checker(theObjectToCheck:*):void
{
theObject = theObjectToCheck;
}
public function property(thisProperty:String, defaultValue:* = null, resultShouldBe:String = null):*
{
var outPut:* = defaultValue;
if (theObject) {
if (theObject.hasOwnProperty(thisProperty)) {
if (resultShouldBe == "justNumbers") {
outPut = ancheck(theObject[thisProperty], defaultValue, "n");
}
if (resultShouldBe == "justAlphas") {
outPut = ancheck(theObject[thisProperty], defaultValue);
}
if (resultShouldBe == "RGBColor") {
outPut = vcolor(null, theObject[thisProperty]);
}
if (resultShouldBe == "6DigitColor") {
outPut = vcolor(theObject[thisProperty], null);
}
if (resultShouldBe == null) {
outPut = theObject[thisProperty];
}
}
}
return outPut;
}
private function ancheck(onthis:*, toreturner:*, aorn:String = "a"):*
{
if (aorn == "a")
{
var alphacheck:int = 0;
for (var i:int = 0; i<onthis.toString().length; i++)
{
if (numz.indexOf(onthis.toString().charAt(i)) != -1)
{alphacheck = 0;}
if (nocs.indexOf(onthis.toString().charAt(i)) != -1)
{alphacheck = 0;}
if (alphaz.indexOf(onthis.toString().charAt(i).toLowerCase()) != -1)
{++alphacheck;}
}
if (alphacheck == onthis.toString().length)
{toreturner = onthis;}
}
else
{
var numon:String = onthis.toString();
if (numon.indexOf(".") != -1)
{numon = numon.replace(/\./g, "");}
var numcheck:int = 0;
for (var j:int = 0; j<numon.length; j++)
{
if (alphaz.indexOf(numon.charAt(j).toLowerCase()) != -1)
{numcheck = 0;}
if (nocs.indexOf(numon.charAt(j)) != -1)
{numcheck = 0;}
if (numz.indexOf(numon.charAt(j)) != -1)
{++numcheck;}
}
if (numcheck == numon.length)
{toreturner = onthis;}
}
return toreturner;
}
public function has(thiser:String):Boolean
{
var outB:Boolean = false;
if (theObject && theObject.hasOwnProperty(thiser)) {outB = true;}
return outB;
}
private function vcolor(color:Object = null, rgb:Object = null):* {
if (rgb == null) {
if ( color == null || color.toString().length != 6 ) {
color = "000000";
} else {
color = color.toString();
var validHex:String = "0123456789ABCDEFabcdef";
var numValid:int = 0;
for (var i:int=0; i < color.length; ++i) {
if (validHex.indexOf(color.charAt(i)) >= 0)
{numValid++;}
}
if (numValid != 6) {color = "000000";}
}
return color;
}
else
{
if (rgb as String != null && rgb.toString().indexOf(",")!=-1) {rgb=rgb.toString().split(",");}
if (rgb as Array != null && rgb.length == 3) {
var rgbvalid:int = 0;
for (var r:int = 0; r < rgb.length; r++)
{
if (rgb[r] as Number >= 0 && rgb[r] as Number <= 255)
{rgbvalid++;}
}
if (rgbvalid != 3) {rgb = [0,0,0];}
}else{rgb = [0,0,0];}
return rgb;
}
}
}
}