<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Exodus.Parsers
{
    public class DefaultAssemblyParser : IAssemblyParser
    {
        public IEnumerable<Task<Migration>> Parse(AssemblyName assemblyName)
        {
            var assembly = Assembly.Load(assemblyName);
            return assembly
                .GetManifestResourceNames()
                .Select(name => new
                {
                    Name = name,
                    Stream = assembly.GetManifestResourceStream(name)
                })
                .Select(async resource =>
                {
                    var migrationId = ParseResourceName(assemblyName, resource.Name);
                    using (var reader = new StreamReader(resource.Stream))
                    {
                        var sql = await reader.ReadToEndAsync();
                        return new Migration(migrationId.version, migrationId.name, sql);
                    }
                });
        }

        private (int version, string name) ParseResourceName(AssemblyName assemblyName, string resourceName)
        {
            var tokens = resourceName
                .Split("-")
                .Select(token => token.Trim())
                .ToArray();
            var version = int.Parse(tokens[0].Split(".").Last());
            var name = tokens[1].Split(".").First();
            return (version, name);
        }
    }
}<commit_msg>assembly parser refactoring<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Exodus.Parsers
{
    public class DefaultAssemblyParser : IAssemblyParser
    {
        public IEnumerable<Task<Migration>> Parse(AssemblyName assemblyName)
        {
            var assembly = Assembly.Load(assemblyName);
            return assembly
                .GetManifestResourceNames()
                .Select(async name =>
                {
                    var migrationId = ParseResourceName(name);
                    var stream = assembly.GetManifestResourceStream(name);
                    using (var reader = new StreamReader(stream))
                    {
                        var sql = await reader.ReadToEndAsync();
                        return new Migration(migrationId.version, migrationId.name, sql);
                    }
                });
        }

        private (int version, string name) ParseResourceName(string resourceName)
        {
            var tokens = resourceName
                .Split("-")
                .Select(token => token.Trim())
                .ToArray();
            var version = int.Parse(tokens[0].Split(".").Last());
            var name = tokens[1].Split(".").First();
            return (version, name);
        }
    }
}
{'fraction_non_alphanumeric': 0.09620596205962059, 'fraction_numerical': 0.0013550135501355014, 'mean_word_length': 1.6319073083778965, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4027277', 'n_tokens_mistral': 706, 'n_tokens_neox': 672, 'n_words': 158}