<commit_before>use v6;
use Config::TOML;
use File::Path::Resolve;
use File::Presence;
use Nightscape::Config::Utils;
use Nightscape::Types;
use TXN::Parser::Grammar;
use TXN::Parser::Types;
use X::Nightscape;
unit class Nightscape::Config::Asset;

# class attributes {{{

has AssetCode:D $.code is required;
has Costing $.costing;
has VarName $.name;
has Hash[Price:D,Date:D] %.price{AssetCode:D};

# end class attributes }}}

# submethod BUILD {{{

submethod BUILD(
    Str:D :$code! where .so,
    Str:D :$scene-file where .so,
    Str :$costing,
    Str :$name,
    :%price
    --> Nil
)
{
    $!code = Nightscape::Config::Utils.gen-asset-code($code);
    $!costing = Nightscape::Config::Utils.gen-costing($costing)
        if $costing;
    $!name = Nightscape::Config::Utils.gen-var-name($name)
        if $name;
    %!price = Nightscape::Config::Utils.gen-price-sheet(%price, $scene-file)
        if %price;
}

# end submethod BUILD }}}
# method new {{{

multi method new(
    *%opts (
        Str:D :code($)! where .so,
        Str:D :scene-file($)! where .so,
        :price(%),
        Str :costing($),
        Str :name($)
    )
    --> Nightscape::Config::Asset:D
)
{
    self.bless(|%opts);
}

multi method new(*% --> Nil)
{
    die(X::Nightscape::Config::Asset::Malformed.new);
}

# end method new }}}
# method hash {{{

method hash(::?CLASS:D: --> Hash:D)
{
    my %hash;
    %hash<code> = $.code;
    %hash<costing> = ~$.costing if $.costing;
    %hash<name> = $.name if $.name;
    %hash<price> = :%.price if %.price;
    %hash;
}

# end method hash }}}
# sub gen-price-sheet {{{

sub gen-price-sheet(
    %price where .so,
    AbsolutePath:D $scene-file where .so
    --> Hash[Hash[Price:D,Date:D],AssetCode:D]
)
{
    my Hash[Price:D,Date:D] %price-sheet{AssetCode:D} =
        %price.kv.hyper.map(-> $asset-code, %asset-code-keypairs {<commit_msg>s/://<commit_after>use v6;
use Config::TOML;
use File::Path::Resolve;
use File::Presence;
use Nightscape::Config::Utils;
use Nightscape::Types;
use TXN::Parser::Grammar;
use TXN::Parser::Types;
use X::Nightscape;
unit class Nightscape::Config::Asset;

# class attributes {{{

has AssetCode:D $.code is required;
has Costing $.costing;
has VarName $.name;
has Hash[Price:D,Date:D] %.price{AssetCode:D};

# end class attributes }}}

# submethod BUILD {{{

submethod BUILD(
    Str:D :$code! where .so,
    Str:D :$scene-file where .so,
    Str :$costing,
    Str :$name,
    :%price
    --> Nil
)
{
    $!code = Nightscape::Config::Utils.gen-asset-code($code);
    $!costing = Nightscape::Config::Utils.gen-costing($costing)
        if $costing;
    $!name = Nightscape::Config::Utils.gen-var-name($name)
        if $name;
    %!price = Nightscape::Config::Utils.gen-price-sheet(%price, $scene-file)
        if %price;
}

# end submethod BUILD }}}
# method new {{{

multi method new(
    *%opts (
        Str:D :code($)! where .so,
        Str:D :scene-file($)! where .so,
        :price(%),
        Str :costing($),
        Str :name($)
    )
    --> Nightscape::Config::Asset:D
)
{
    self.bless(|%opts);
}

multi method new(*% --> Nil)
{
    die(X::Nightscape::Config::Asset::Malformed.new);
}

# end method new }}}
# method hash {{{

method hash(::?CLASS:D: --> Hash:D)
{
    my %hash;
    %hash<code> = $.code;
    %hash<costing> = ~$.costing if $.costing;
    %hash<name> = $.name if $.name;
    %hash<price> = %.price if %.price;
    %hash;
}

# end method hash }}}
# sub gen-price-sheet {{{

sub gen-price-sheet(
    %price where .so,
    AbsolutePath:D $scene-file where .so
    --> Hash[Hash[Price:D,Date:D],AssetCode:D]
)
{
    my Hash[Price:D,Date:D] %price-sheet{AssetCode:D} =
        %price.kv.hyper.map(-> $asset-code, %asset-code-keypairs {
{'fraction_non_alphanumeric': 0.19645256651437787, 'fraction_numerical': 0.0005374899220639613, 'mean_word_length': 3.268348623853211, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, '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': '5263074', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1393, 'n_words': 296}