Esempio n. 1
0
 public void Open(string filepath)
 {
     string[] lines =
         new StreamReader(_fileSystem.OpenFileForRead(filepath)).ReadToEnd().Split(new string[] {"\r\n", "\n"}, StringSplitOptions.None);
     _records = new Queue<Record>(lines.Where(line => !string.IsNullOrWhiteSpace(line)).Select(ParseRecord));
     _current = null;
 }
Esempio n. 2
0
        public PresidentRecordReader(Record record)
        {
            if (record == null) {
                throw new ArgumentNullException("record");
            }
            if (record.Fields.Length != 9) {
                throw new FormatException(
                    string.Format("President record must contain exactly 9 fields, but given record contains {0}.",
                        record.Fields.Length));
            }

            Presidency = ValidateAndGetNumber(record.Fields[0], "presidency");

            Name = ValidateAndGetPersonFullName(record.Fields[1], "name");

            Uri wikiUrl;
            if (!Uri.TryCreate(record.Fields[2], UriKind.RelativeOrAbsolute, out wikiUrl)) {
                throw new FormatException("Wiki link is not a valid URL.");
            }
            WikipediaEntryUrl = wikiUrl;

            TookOffice = ValidateAndGetDateTime(record.Fields[3], "took office date");

            LeftOffice = ValidateAndGetDateTime(record.Fields[4], "left office date");

            Party = ValidateAndGetString(record.Fields[5], "party");

            PortraitImageFilename = ValidateAndGetString(record.Fields[6], "portrait image");

            ThumbnailImageFilename = ValidateAndGetString(record.Fields[7], "thumbnail image");

            HomeState = ValidateAndGetString(record.Fields[8], "home state");
        }
Esempio n. 3
0
 public bool MoveNext()
 {
     if (_records.Any()) {
         _current = _records.Dequeue();
         return true;
     }
     return false;
 }
Esempio n. 4
0
 public bool ShouldPass(Record record)
 {
     return new PresidentRecordReader(record).HomeState.Equals(_state);
 }
Esempio n. 5
0
 public bool ShouldPass(Record record)
 {
     return _predicate(record);
 }
Esempio n. 6
0
 protected bool Equals(Record other)
 {
     return this.Fields.SequenceEqual(other.Fields);
 }