diff options
author | Serghei Cebotari <serghei@cebotari.ru> | 2023-10-22 13:43:18 +0300 |
---|---|---|
committer | Serghei Cebotari <serghei@cebotari.ru> | 2023-10-22 13:43:18 +0300 |
commit | b91d8fbe99ac56155e6b7547d2e4931832eeb9f4 (patch) | |
tree | c3746de9b60d76870f8327387b04b765fb209375 /RhSolutions.QueryModifiers/DrinkingWaterHeatingPipes/DrinkingWaterHeatingPipe.cs | |
parent | 020922d749ab0f53fc178700e2181487be9a05ee (diff) |
Remove BuildRhSolutionsName methods
Diffstat (limited to 'RhSolutions.QueryModifiers/DrinkingWaterHeatingPipes/DrinkingWaterHeatingPipe.cs')
-rw-r--r-- | RhSolutions.QueryModifiers/DrinkingWaterHeatingPipes/DrinkingWaterHeatingPipe.cs | 92 |
1 files changed, 43 insertions, 49 deletions
diff --git a/RhSolutions.QueryModifiers/DrinkingWaterHeatingPipes/DrinkingWaterHeatingPipe.cs b/RhSolutions.QueryModifiers/DrinkingWaterHeatingPipes/DrinkingWaterHeatingPipe.cs index 5c1bfd9..1420d03 100644 --- a/RhSolutions.QueryModifiers/DrinkingWaterHeatingPipes/DrinkingWaterHeatingPipe.cs +++ b/RhSolutions.QueryModifiers/DrinkingWaterHeatingPipes/DrinkingWaterHeatingPipe.cs @@ -1,62 +1,56 @@ using System.Text.RegularExpressions; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Extensions; namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes; public class DrinkingWaterHeatingPipe : IProductQueryModifier { - protected static readonly Regex _diameter = - new(@"([\b\D]|^)?(?<Diameter>16|20|25|32|40|50|63)([\b\D]|$)"); - protected static readonly Regex _type = - new(@"([\b\W])(?<Type>бухт|отр|штанг)([\b\w\.\s])"); - protected virtual string _title { get; } = string.Empty; + protected static readonly Regex _diameter = + new(@"([\b\D]|^)?(?<Diameter>16|20|25|32|40|50|63)([\b\D]|$)"); + protected static readonly Regex _type = + new(@"([\b\W])(?<Type>бухт|отр|штанг)([\b\w\.\s])"); + protected virtual string _title { get; } = string.Empty; - protected virtual Dictionary<int, string> _diameterNames { get; } = new() - { - [16] = "16x2,2", - [20] = "20x2,8", - [25] = "25x3,5", - [32] = "32x4,4", - [40] = "40x5,5", - [50] = "50x6,9", - [63] = "63x8,6" - }; + protected virtual Dictionary<int, string> _diameterNames { get; } = new() + { + [16] = "16x2,2", + [20] = "20x2,8", + [25] = "25x3,5", + [32] = "32x4,4", + [40] = "40x5,5", + [50] = "50x6,9", + [63] = "63x8,6" + }; - protected virtual Dictionary<string, string> _makeUp { get; } = new() - { - ["бухт"] = "бухта", - ["штанг"] = "прям.отрезки", - ["отр"] = "прям.отрезки" - }; + protected virtual Dictionary<string, string> _makeUp { get; } = new() + { + ["бухт"] = "бухта", + ["штанг"] = "прям.отрезки", + ["отр"] = "прям.отрезки" + }; public bool TryQueryModify(string input, out string output) { - output = BuildRhSolutionsName(input) ?? string.Empty; - return !string.IsNullOrEmpty(output); + output = string.Empty; + var diameterMatch = _diameter.Match(input); + if (!diameterMatch.Success) + { + return false; + } + var diameter = int.Parse(diameterMatch.Groups["Diameter"].Value); + var typeMatch = _type.Match(input); + if (typeMatch.Success) + { + var type = typeMatch.Groups["Type"].Value; + output = $"Труба {_title} {_diameterNames[diameter]} {_makeUp[type]}"; + } + else if (diameter < 32) + { + output = $"Труба {_title} {_diameterNames[diameter]} {_makeUp["бухт"]}"; + } + else + { + output = $"Труба {_title} {_diameterNames[diameter]} {_makeUp["отр"]}"; + } + return true; } - - protected virtual string? BuildRhSolutionsName(string query) - { - var diameterMatch = _diameter.Match(query); - if (!diameterMatch.Success) - { - return null; - } - var diameter = int.Parse(diameterMatch.Groups["Diameter"].Value); - var typeMatch = _type.Match(query); - if (typeMatch.Success) - { - var type = typeMatch.Groups["Type"].Value; - return $"Труба {_title} {_diameterNames[diameter]} {_makeUp[type]}"; - } - else if (diameter < 32) - { - return $"Труба {_title} {_diameterNames[diameter]} {_makeUp["бухт"]}"; - } - else - { - return $"Труба {_title} {_diameterNames[diameter]} {_makeUp["отр"]}"; - } - } } |