-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReceiptFormatParser.cs
37 lines (32 loc) · 1.03 KB
/
ReceiptFormatParser.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using ReceiptParser.ReceiptParser.Interface;
using ReceiptParser.ReceiptParser.Interface.Input;
using ReceiptParser.ReceiptParser.Interface.Output;
namespace ReceiptParser
{
public class ReceiptFormatParser : IReceiptFormatParser
{
public ReceiptFormat ParseReceiptFormat(ReceiptDataIn receipt)
{
if(receipt == null)
{
throw new ArgumentNullException("receipt");
}
if(string.IsNullOrWhiteSpace(receipt.RawText))
{
throw new ArgumentException("receipt.RawText is null or white space");
}
var rawText = receipt.RawText;
string[] lines = rawText.Split('\n');
if (lines.Length >= 3)
{
if (lines[0].StartsWith("ABC") &&
lines[2].StartsWith("KORTTIAUTOMAATTI"))
{
return ReceiptFormat.Fuel_Abc;
}
}
return ReceiptFormat.Unknown;
}
}
}