summaryrefslogtreecommitdiff
path: root/RhSolutions.Parsers/DrinkingWaterHeatingFittings/DrinkingWaterHeatingFitting.cs
blob: 867e886c68678317558d1cdf8ca158eefc5419f6 (plain)
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
38
39
using System.Text.RegularExpressions;

namespace RhSolutions.Parsers.Fittings;

public abstract class DrinkingWaterHeatingFitting : IProductParser
{
    protected static readonly Regex _diameter =
        new(@"(?<!^|\d)(?<Diameter>16|20|25|32|40|50|63|14|15|26)(?!\d)");
    protected static readonly Regex _angle =
        new(@"(?<!^|\d)(?<Angle>45|90)(?!\d)");
    protected static readonly Regex _thread =
        new(@"(?<!^|\d)(?<Thread>1\s+1/4|1\s+1/2|1/2|3/4|2|1)(?!\d)");

    protected virtual string _title { get; } = string.Empty;

    public virtual bool TryParse(string input, out string output)
    {
        var match = _diameter.Match(input);
        if (match.Success)
        {
            output = $"{_title} {match.Groups["Diameter"]}";
            return true;
        }
        else
        {
            output = string.Empty;
            return false;
        }
    }
    protected string NormalizeDiameter(string diameter)
    {
        return diameter switch
        {
            "14" => "16",
            "26" => "25",
            _ => diameter
        };
    }
}