summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerghei Cebotari <serghei@cebotari.ru>2025-02-19 11:20:28 +0300
committerSerghei Cebotari <serghei@cebotari.ru>2025-02-19 11:20:28 +0300
commitd5106cd0f47a357f54f6d1daa0bb6dda1d8c5f8a (patch)
tree7550265a32768842a195809ffe257a0b7037e2ad
parenta864f851782a9d18fff7fb0d97cbb661d25b6f88 (diff)
Add diameter threads support
-rw-r--r--RhSolutions.Parsers.Tests/RautitanFittingsTests.cs1
-rw-r--r--RhSolutions.Parsers/DrinkingWaterHeatingFittings/Adapter.cs23
-rw-r--r--RhSolutions.Parsers/DrinkingWaterHeatingFittings/DrinkingWaterHeatingFitting.cs2
3 files changed, 19 insertions, 7 deletions
diff --git a/RhSolutions.Parsers.Tests/RautitanFittingsTests.cs b/RhSolutions.Parsers.Tests/RautitanFittingsTests.cs
index bff454f..dd40d75 100644
--- a/RhSolutions.Parsers.Tests/RautitanFittingsTests.cs
+++ b/RhSolutions.Parsers.Tests/RautitanFittingsTests.cs
@@ -37,6 +37,7 @@ public class RautitanFittingsTests : ProductParsersTests
[TestCase("Переходник с внутренней резьбой 16xG 3/4\" для труб из сшитого полиэтилена аксиальный", "Переходник с внутренней резьбой -угольник-переходник 16 3/4")]
[TestCase("Переходник на внутреннюю резьбу 20", "Переходник с внутренней резьбой -угольник-переходник 20 1/2")]
[TestCase("32 Соединение прямое с внутренней резьбой, 40 х 1 1/2", "Переходник с внутренней резьбой -угольник-переходник 40 1 1/2")]
+ [TestCase("Переходник с вн. резьбой 16 20", "Переходник с внутренней резьбой -угольник-переходник 16 3/4")]
public void AdapterInternalTest(string query, string modified)
=> Invoke(productType: "Переходник на внутреннюю резьбу", query, modified);
diff --git a/RhSolutions.Parsers/DrinkingWaterHeatingFittings/Adapter.cs b/RhSolutions.Parsers/DrinkingWaterHeatingFittings/Adapter.cs
index 8ef4f33..3600cc8 100644
--- a/RhSolutions.Parsers/DrinkingWaterHeatingFittings/Adapter.cs
+++ b/RhSolutions.Parsers/DrinkingWaterHeatingFittings/Adapter.cs
@@ -15,24 +15,35 @@ public abstract class Adapter : DrinkingWaterHeatingFitting
["63"] = "2"
};
public override bool TryParse(string input, out string output)
- {
+ {
output = string.Empty;
- Match diameter = _diameter.Match(input);
- if (!diameter.Success)
+ MatchCollection diameters = _diameter.Matches(input);
+ if (diameters.Count < 1)
{
return false;
}
Match thread = _thread.Match(input);
string threadValue;
- if (!thread.Success)
+ if (!thread.Success && diameters.Count >= 2)
+ {
+ var diameterThread = diameters[1].Groups["Diameter"];
+ threadValue = diameterThread.Value switch
+ {
+ "15" => "1/2",
+ "20" => "3/4",
+ "25" => "1",
+ _ => string.Empty
+ };
+ }
+ else if (!thread.Success)
{
- threadValue = _defaultThreads[diameter.Groups["Diameter"].Value];
+ threadValue = _defaultThreads[diameters[0].Groups["Diameter"].Value];
}
else
{
threadValue = thread.Groups["Thread"].Value;
}
- output = $"{_title} {diameter.Groups["Diameter"]} {threadValue}";
+ output = $"{_title} {diameters[0].Groups["Diameter"]} {threadValue}";
return true;
}
}
diff --git a/RhSolutions.Parsers/DrinkingWaterHeatingFittings/DrinkingWaterHeatingFitting.cs b/RhSolutions.Parsers/DrinkingWaterHeatingFittings/DrinkingWaterHeatingFitting.cs
index 5658766..fcd2544 100644
--- a/RhSolutions.Parsers/DrinkingWaterHeatingFittings/DrinkingWaterHeatingFitting.cs
+++ b/RhSolutions.Parsers/DrinkingWaterHeatingFittings/DrinkingWaterHeatingFitting.cs
@@ -5,7 +5,7 @@ namespace RhSolutions.Parsers.Fittings;
public abstract class DrinkingWaterHeatingFitting : IProductParser
{
protected static readonly Regex _diameter =
- new(@"(?<!^)[\b\D]?(?<Diameter>16|20|25|32|40|50|63)[\b\D]?");
+ new(@"(?<!^)[\b\D]?(?<Diameter>16|20|25|32|40|50|63|15)[\b\D]?");
protected static readonly Regex _angle =
new(@"(?<!^)([\b\D])(?<Angle>45|90)([\b\D]|$)");
protected static readonly Regex _thread =