public Species[] ToArray()
            {
                switch (OrderBy)
                {
                case OrderBy.Newest:
                    Items.Sort((lhs, rhs) => rhs.Timestamp.CompareTo(lhs.Timestamp));
                    break;

                case OrderBy.Oldest:
                    Items.Sort((lhs, rhs) => lhs.Timestamp.CompareTo(rhs.Timestamp));
                    break;

                case OrderBy.Smallest:
                    Items.Sort((lhs, rhs) => SpeciesSizeMatch.Match(lhs.Description).MaxSize.ToMeters().CompareTo(SpeciesSizeMatch.Match(rhs.Description).MaxSize.ToMeters()));
                    break;

                case OrderBy.Largest:
                    Items.Sort((lhs, rhs) => SpeciesSizeMatch.Match(rhs.Description).MaxSize.ToMeters().CompareTo(SpeciesSizeMatch.Match(lhs.Description).MaxSize.ToMeters()));
                    break;

                default:
                case OrderBy.Default:
                    Items.Sort((lhs, rhs) => lhs.ShortName.CompareTo(rhs.ShortName));
                    break;
                }

                return(Items.ToArray());
            }
Пример #2
0
        public async Task Size(Species species, LengthUnit units)
        {
            // Attempt to get the size of the species.

            SpeciesSizeMatch match = SpeciesSizeMatch.Match(species.Description);

            // Output the result.

            EmbedBuilder embed = new EmbedBuilder();

            embed.Title = string.Format("Size of {0}", species.FullName);
            embed.WithDescription(units == LengthUnit.Unknown ? match.ToString() : match.ToString(units));
            embed.WithFooter("Size is determined from species description, and may not be accurate.");

            await ReplyAsync("", false, embed.Build());
        }
Пример #3
0
        // Public members

        public override async Task ApplyAsync(ISearchContext context, ISearchResult result)
        {
            switch (ParseOrderBy(Value))
            {
            case OrderBy.Newest:
                await result.OrderByAsync(Comparer <ISpecies> .Create((lhs, rhs) => rhs.CreationDate.CompareTo(lhs.CreationDate)));

                break;

            case OrderBy.Oldest:
                await result.OrderByAsync(Comparer <ISpecies> .Create((lhs, rhs) => lhs.CreationDate.CompareTo(rhs.CreationDate)));

                break;

            case OrderBy.Smallest:
                await result.OrderByAsync(Comparer <ISpecies> .Create((lhs, rhs) => SpeciesSizeMatch.Match(lhs.Description).MaxSize.ToMeters().CompareTo(SpeciesSizeMatch.Match(rhs.Description).MaxSize.ToMeters())));

                break;

            case OrderBy.Largest:
                await result.OrderByAsync(Comparer <ISpecies> .Create((lhs, rhs) => SpeciesSizeMatch.Match(rhs.Description).MaxSize.ToMeters().CompareTo(SpeciesSizeMatch.Match(lhs.Description).MaxSize.ToMeters())));

                break;

            case OrderBy.Count:
                await result.OrderByAsync(Comparer <ISearchResultGroup> .Create((lhs, rhs) => rhs.Count().CompareTo(lhs.Count())));

                break;

            case OrderBy.Suffix:
                await result.OrderByAsync(Comparer <ISpecies> .Create((lhs, rhs) => {
                    string lhsStr = new string(result.TaxonFormatter.GetString(lhs, false).Reverse().ToArray());
                    string rhsStr = new string(result.TaxonFormatter.GetString(rhs, false).Reverse().ToArray());

                    return(lhsStr.CompareTo(rhsStr));
                }));

                break;

            default:
            case OrderBy.Default:
                await result.OrderByAsync(Comparer <ISpecies> .Create((lhs, rhs) => result.TaxonFormatter.GetString(lhs, false).CompareTo(result.TaxonFormatter.GetString(rhs, false))));

                break;
            }
        }
Пример #4
0
        // Public members

        public async override Task ApplyAsync(ISearchContext context, ISearchResult result)
        {
            switch (ParseHasType(Value))
            {
            case HasType.Prey:
                await result.FilterByAsync(async (species) => (await context.Database.GetPreyAsync(species)).Count() <= 0, Invert);

                break;

            case HasType.Predator:
                await result.FilterByAsync(async (species) => (await context.Database.GetPredatorsAsync(species)).Count() <= 0, Invert);

                break;

            case HasType.Ancestor:
                await result.FilterByAsync(async (species) => await context.Database.GetAncestorAsync(species, GetSpeciesOptions.Fast) is null, Invert);

                break;

            case HasType.Descendant:
                await result.FilterByAsync(async (species) => (await context.Database.GetDirectDescendantsAsync(species)).Count() <= 0, Invert);

                break;

            case HasType.Role:
                await result.FilterByAsync(async (species) => (await context.Database.GetRolesAsync(species)).Count() <= 0, Invert);

                break;

            case HasType.Picture:
                await result.FilterByAsync(async (species) => (await context.Database.GetPicturesAsync(species)).Count() <= 0, Invert);

                break;

            case HasType.Size:
                await result.FilterByAsync(async (species) => await Task.FromResult(!SpeciesSizeMatch.Match(species.Description).Success), Invert);

                break;
            }
        }
        public void TestToStringWithFeet()
        {
            SpeciesSizeMatch match = SpeciesSizeMatch.Match("4.8 feet");

            Assert.AreEqual("**1.5 m** (4.8 ft)", match.ToString());
        }
        public void TestToStringWithCentimeters()
        {
            SpeciesSizeMatch match = SpeciesSizeMatch.Match("15 cm");

            Assert.AreEqual("**15 cm** (5.9 in)", match.ToString());
        }