aboutsummaryrefslogtreecommitdiff
path: root/src/Assistant/RequestModifier.cs
diff options
context:
space:
mode:
authorSerghei Cebotari <51533848+schebotar@users.noreply.github.com>2021-12-26 19:37:46 +0300
committerGitHub <noreply@github.com>2021-12-26 19:37:46 +0300
commitfc870d19555cc77b0e08912b4dab21d496b2321f (patch)
treeac8b9aa1e883a85339a594b2797ab319cca73c4e /src/Assistant/RequestModifier.cs
parent0525ec1b42d5857b740dd0dae7f6d9baeb7088d1 (diff)
parent54fc3320e7d64d7903b4d091fe0d5c15df01fd78 (diff)
Merge pull request #9 from schebotar/dev
Move to /src
Diffstat (limited to 'src/Assistant/RequestModifier.cs')
-rw-r--r--src/Assistant/RequestModifier.cs67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/Assistant/RequestModifier.cs b/src/Assistant/RequestModifier.cs
new file mode 100644
index 0000000..9f42e71
--- /dev/null
+++ b/src/Assistant/RequestModifier.cs
@@ -0,0 +1,67 @@
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+
+namespace RehauSku.Assistant
+{
+ public static class RequestModifier
+ {
+ public static string CleanRequest(this string input)
+ {
+ string replace = new StringBuilder(input)
+ .Replace("+", " plus ")
+ .Replace("РХ", "")
+ .Replace("º", " ")
+ .Replace(".", " ")
+ .Replace("Ø", " ")
+ .ToString();
+
+ return replace._tPieceNormalize();
+ }
+
+ private static string _tPieceNormalize(this string line)
+ {
+ Regex regex = new Regex(@"\d{2}.\d{2}.\d{2}");
+
+ if (!regex.IsMatch(line))
+ return line;
+
+ string match = regex.Match(line).Value;
+
+ int side = int.Parse($"{match[3]}{match[4]}");
+ int[] endFaces = new int[]
+ {
+ int.Parse($"{match[0]}{match[1]}"),
+ int.Parse($"{match[6]}{match[7]}")
+ };
+
+ if (new[] { endFaces[0], endFaces[1], side }.Any(x => x == 45 || x == 90 || x == 87))
+ return line;
+
+ List<string> additions = new List<string>();
+
+ if (endFaces.All(x => x < side))
+ additions.Add("увеличенный боковой");
+
+ else
+ {
+ if (new[] { endFaces[0], endFaces[1], side }.Distinct().Count() == 1)
+ additions.Add("равнопроходной");
+ else
+ additions.Add("уменьшенный");
+
+ if (endFaces.Any(x => x > side))
+ additions.Add("боковой");
+
+ if (endFaces[0] != endFaces[1])
+ additions.Add("торцевой");
+ }
+
+ string piece = $" {endFaces.Max()}-{side}-{endFaces.Min()} ";
+ string modifiedMatch = string.Join(" ", additions) + piece;
+
+ return line.Replace(match, modifiedMatch);
+ }
+ }
+} \ No newline at end of file