Exemplo n.º 1
0
        public Run Cite(IEnumerable <string> keys)
        {
            var list = new List <Citation>();

            foreach (var key in keys)
            {
                if (!citedCitations.TryGetValue(key, out var citation))
                {
                    if (!citations.TryGetValue(key, out citation))
                    {
                        throw new Exception();
                    }
                    else
                    {
                        citedCitations[key]         = citation;
                        citation["citation-number"] = new TextVariable(citedCitations.Count.ToString());
                    }
                }

                list.Add(citation);
            }

            return(Processor.Cite(Locale, list));
        }
Exemplo n.º 2
0
        public static Citation Parse(JsonElement json)
        {
            var properties = json.EnumerateObject();
            var id         = string.Empty;

            if (json.TryGetProperty("id", out var idElement))
            {
                id = idElement.ToString();
            }
            var type = string.Empty;

            if (json.TryGetProperty("type", out var typeElement))
            {
                type = typeElement.ToString();
            }
            var cb = new CitationBuilder(id, type);

            foreach (var property in properties)
            {
                IVariable variable;
                switch (property.Name)
                {
                case "chapter-number":
                case "collection-number":
                case "edition":
                case "issue":
                case "number":
                case "number-of-pages":
                case "number-of-volumes":
                case "volume":
                    variable = ParseNumber(property.Value);
                    break;

                case "page":
                    var num = ParseNumber(property.Value);
                    variable = num;
                    cb.Set(new NumberVariable(num.Min), "page-first");
                    break;

                case "accessed":
                case "container":
                case "event-date":
                case "issued":
                case "original-date":
                case "submitted":
                    variable = ParseDate(property.Value);
                    break;

                case "author":
                case "collection-author":
                case "composer":
                case "container-author":
                case "director":
                case "editor":
                case "editorial-director":
                case "illustrator":
                case "interviewer":
                case "original-author":
                case "recipient":
                case "reviewed-author":
                case "translator":
                    variable = ParseName(property.Value);
                    break;

                default:
                    variable = new TextVariable(property.Value.ToString());
                    break;
                }
                cb.Set(variable, property.Name);
            }

            return(cb.Build());
        }
Exemplo n.º 3
0
 public CitationBuilder(string key, string type)
 {
     citation = new Citation(key);
     citation[nameof(type)] = new TextVariable(type);
 }
Exemplo n.º 4
0
 public CitationBuilder(string key, CitationType type)
 {
     citation = new Citation(key);
     citation[nameof(type)] = new TextVariable(TransformType(type));
 }