001package edu.pdx.cs410J.phonebill;
002
003import edu.pdx.cs410J.ParserException;
004import edu.pdx.cs410J.PhoneBillParser;
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 PhoneBillParser<PhoneBill> {
014  private final Reader reader;
015
016  public TextParser(Reader reader) {
017    this.reader = reader;
018  }
019
020  @Override
021  public PhoneBill parse() throws ParserException {
022    try (
023      BufferedReader br = new BufferedReader(this.reader)
024    ) {
025
026      String customer = br.readLine();
027
028      if (customer == null) {
029        throw new ParserException("Missing customer");
030      }
031
032      return new PhoneBill(customer);
033
034    } catch (IOException e) {
035      throw new ParserException("While parsing phone bill text", e);
036    }
037  }
038}