private double?ToFee(Tockenizer <EurekahedgeLockupTokenType> .TokenMatch percentMatch)
        {
            double result;

            return(double.TryParse(percentMatch.Value.Substring(0, percentMatch.Value.Length - 1), NumberStyles.Float, formatProvider, out result)
                ? result
                : (double?)null);
        }
        private LockupValue Parce(List <EurekahedgeLockupTockenizer.TokenMatch> tokens)
        {
            LockupValue result = new LockupValue();

            // Duration, Period
            Tockenizer <EurekahedgeLockupTokenType> .TokenMatch numberMatch;
            Tockenizer <EurekahedgeLockupTokenType> .TokenMatch periodMatch;
            FindNumberPeriodPattern(tokens, out numberMatch, out periodMatch);
            if (numberMatch != null)
            {
                result.LockupDuration = ToDuration(numberMatch, periodMatch);
            }
            if (periodMatch != null)
            {
                result.LockupPeriod = ToPeriod(periodMatch.TokenType);
            }

            // Fee
            Tockenizer <EurekahedgeLockupTokenType> .TokenMatch percentMatch = tokens.FirstOrDefault(x => x.TokenType == EurekahedgeLockupTokenType.PercentValue);
            if (percentMatch != null)
            {
                result.LockupFee = ToFee(percentMatch);
            }

            // LockupType
            Tockenizer <EurekahedgeLockupTokenType> .TokenMatch softOrHardMatch = tokens.FirstOrDefault(x => IsSoftOrHard(x.TokenType));
            if (softOrHardMatch != null)
            {
                result.LockupType = softOrHardMatch.TokenType == EurekahedgeLockupTokenType.Hard ? LockupType.Hard : LockupType.Soft;
            }
            else if (percentMatch != null)
            {
                result.LockupType = LockupType.Soft;
            }
            else if (periodMatch != null)
            {
                result.LockupType = tokens.Any(x => x.TokenType == EurekahedgeLockupTokenType.No) ? LockupType.Soft : LockupType.Hard;
            }
            else if (tokens.Any(x => x.TokenType == EurekahedgeLockupTokenType.Yes))
            {
                result.LockupType = LockupType.Hard;
            }

            if (!result.LockupFee.HasValue && (!result.LockupDuration.HasValue || !result.LockupPeriod.HasValue))
            {
                if (tokens.Exists(x => IsPeriodType(x.TokenType)) || tokens.Exists(x => IsNumberType(x.TokenType)))
                {
                    result.Warning = true;
                }
            }

            return(result);
        }
示例#3
0
        private int?ToDuration(Tockenizer <EurekahedgeLockupTokenType> .TokenMatch numberMatch, Tockenizer <EurekahedgeLockupTokenType> .TokenMatch periodMatch)
        {
            double result;

            if (numberMatch == null)
            {
                result = 1;
            }
            else if (numberMatch.TokenType == EurekahedgeLockupTokenType.WordNumberValue)
            {
                result = ToNumber(numberMatch.Value);
            }
            else if (!double.TryParse(numberMatch.Value, NumberStyles.Float, formatProvider, out result))
            {
                return(null);
            }

            double multi;

            switch (periodMatch.TokenType)
            {
            case EurekahedgeLockupTokenType.Year:
                multi = 12;
                break;

            case EurekahedgeLockupTokenType.Quarter:
                multi = 3;
                break;

            case EurekahedgeLockupTokenType.Month:
            case EurekahedgeLockupTokenType.Week:
            case EurekahedgeLockupTokenType.Day:
                multi = 1;
                break;

            default:
                return(null);
            }

            return((int)Math.Truncate(result * multi));
        }