JBZoo\SimpleTypes\Type\Type::_customConvert PHP Method

_customConvert() protected method

protected _customConvert ( string $rule, boolean $addToLog = false ) : float
$rule string
$addToLog boolean
return float
    protected function _customConvert($rule, $addToLog = false)
    {
        $from = $this->_parser->checkRule($this->_rule);
        $target = $this->_parser->checkRule($rule);
        $ruleTo = $this->_formatter->get($target);
        $ruleFrom = $this->_formatter->get($from);
        $ruleDef = $this->_formatter->get($this->_default);
        $log = '"' . $from . '"=>"' . $target . '"';
        $result = $this->_value;
        if ($from !== $target) {
            if (is_callable($ruleTo['rate']) || is_callable($ruleFrom['rate'])) {
                if (is_callable($ruleFrom['rate'])) {
                    $defNorm = $ruleFrom['rate']($this->_value, $this->_default, $from);
                } else {
                    $defNorm = $this->_value * $ruleFrom['rate'] * $ruleDef['rate'];
                }
                if (is_callable($ruleTo['rate'])) {
                    $result = $ruleTo['rate']($defNorm, $target, $this->_default);
                } else {
                    $result = $defNorm / $ruleTo['rate'];
                }
            } else {
                $defNorm = $this->_value * $ruleFrom['rate'] * $ruleDef['rate'];
                $result = $defNorm / $ruleTo['rate'];
            }
            if ($this->_isDebug && $addToLog) {
                $message = array('Converted ' . $log . ';', 'New value = "' . $result . ' ' . $target . '";', is_callable($ruleTo['rate']) ? 'func(' . $from . ')' : $ruleTo['rate'] . ' ' . $from, '=', is_callable($ruleFrom['rate']) ? 'func(' . $target . ')' : $ruleFrom['rate'] . ' ' . $target);
                $this->log(implode(' ', $message));
            }
        }
        return $result;
    }