001package edu.pdx.cs410J.airline;
002
003import edu.pdx.cs410J.AirlineParser;
004import edu.pdx.cs410J.ParserException;
005
006import java.io.BufferedReader;
007import java.io.IOException;
008import java.io.Reader;
009
010/**
011 * A skeletal implementation of the <code>TextParser</code> class for Project 2.
012 */
013public class TextParser implements AirlineParser<Airline> {
014  private final Reader reader;
015
016  public TextParser(Reader reader) {
017    this.reader = reader;
018  }
019
020  @Override
021  public Airline parse() throws ParserException {
022    try (
023      BufferedReader br = new BufferedReader(this.reader)
024    ) {
025
026      String airlineName = br.readLine();
027
028      if (airlineName == null) {
029        throw new ParserException("Missing airline name");
030      }
031
032      return new Airline(airlineName);
033
034    } catch (IOException e) {
035      throw new ParserException("While parsing airline text", e);
036    }
037  }
038}