1  /**
     2   * com.sekati.convert.BoolConversion
     3   * @version 1.0.0
     4   * @author jason m horwitz | sekati.com
     5   * Copyright (C) 2007  jason m horwitz, Sekat LLC. All Rights Reserved.
     6   * Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
     7   */
     8   
     9  /**
    10   * Boolean Conversion utilities
    11   */
    12  class com.sekati.convert.BoolConversion {
    13  
    14  	/**
    15  	 * Convert string to boolean
    16  	 * @param str (String) boolean string ("1", "true", "yes", "on")
    17  	 * @return Boolean
    18  	 * {@code Usage:
    19  	 * 	var b:Boolean = BoolConversion.toBoolean("true");
    20  	 * }
    21  	 */
    22  	public static function toBoolean(str:String):Boolean {
    23  		var b:String = str.toLowerCase( );
    24  		if (b == "1" || b == "true" || b == "yes" || b == "on") {
    25  			return true;
    26  		} else if ( b == "0" || b == "false" || b == "no" || b == "off") {
    27  			return false;
    28  		}
    29  	}
    30  
    31  	/**
    32  	 * Convert boolean value to string
    33  	 * @param b (Boolean)
    34  	 * @return String
    35  	 * {@code Usage:
    36  	 * 	var str:String = BoolConversion.toString(true);
    37  	 * }
    38  	 */
    39  	public static function toString(b:Boolean):String {
    40  		var str:String = (b) ? "true" : "false";
    41  		return str;
    42  	}
    43  
    44  	private function BoolConversion() {
    45  	}
    46  }