<commit_before>package Curses::UI::Number;

# Pragmas.
use base qw(Curses::UI::Label);
use strict;
use warnings;

# Modules.
use Curses::UI::Common qw(keys_to_lowercase);
use Curses::UI::Label;
use Encode qw(decode_utf8);

# Version.
our $VERSION = 0.01;

# Constructor.
sub new {
	my ($class, %userargs) = @_;
	keys_to_lowercase(\%userargs);
	my %args = (
		'-num' => undef,
		'-char' => decode_utf8('█'),
		%userargs,
	);

	# Text.
	$args{'-text'} = _text($args{'-char'}, $args{'-num'});

	# Create the widget.
	my $self = $class->SUPER::new(%args);

	# Layout.
	$self->layout;

	# Return object.
	return $self;
}

# Get or set number.
sub num {
	my ($self, $number) = @_;
	if (defined $number) {
		$self->{'-num'} = $number;
		$self->{'-text'} = _text($self->{'-char'}, $number);
	}
	return $self->{'-num'};
}

# Convert number to text.
sub _text {
	my ($char, $number) = @_;
	my $text = '';
	my $num_ar = _num($number);
	foreach my $i (0 .. 14) {
		if ($num_ar->[$i]) {
			$text .= $char x 2;
		} else {
			$text .= '  ';
		}
		if ($i != 14 && ($i + 1) % 3 == 0) {
			$text .= "\n";
		}
	}
	return $text;
}

# Return structure of pixels.
sub _num {
	my $number = shift;
	return [
		[1,1,1,1,0,1,1,0,1,1,0,1,1,1,1], # 0
		[0,0,1,0,0,1,0,0,1,0,0,1,0,0,1], # 1
		[1,1,1,0,0,1,1,1,1,1,0,0,1,1,1], # 2
		[1,1,1,0,0,1,1,1,1,0,0,1,1,1,1], # 3
		[1,0,1,1,0,1,1,1,1,0,0,1,0,0,1], # 4
		[1,1,1,1,0,0,1,1,1,0,0,1,1,1,1], # 5
		[1,1,1,1,0,0,1,1,1,1,0,1,1,1,1], # 6
		[1,1,1,0,0,1,0,0,1,0,0,1,0,0,1], # 7
		[1,1,1,1,0,1,1,1,1,1,0,1,1,1,1], # 8
		[1,1,1,1,0,1,1,1,1,0,0,1,1,1,1], # 9
	]->[$number];
}

1;<commit_msg>Sort subroutines.<commit_after>package Curses::UI::Number;

# Pragmas.
use base qw(Curses::UI::Label);
use strict;
use warnings;

# Modules.
use Curses::UI::Common qw(keys_to_lowercase);
use Curses::UI::Label;
use Encode qw(decode_utf8);

# Version.
our $VERSION = 0.01;

# Constructor.
sub new {
	my ($class, %userargs) = @_;
	keys_to_lowercase(\%userargs);
	my %args = (
		'-num' => undef,
		'-char' => decode_utf8('█'),
		%userargs,
	);

	# Text.
	$args{'-text'} = _text($args{'-char'}, $args{'-num'});

	# Create the widget.
	my $self = $class->SUPER::new(%args);

	# Layout.
	$self->layout;

	# Return object.
	return $self;
}

# Get or set number.
sub num {
	my ($self, $number) = @_;
	if (defined $number) {
		$self->{'-num'} = $number;
		$self->{'-text'} = _text($self->{'-char'}, $number);
	}
	return $self->{'-num'};
}

# Return structure of pixels.
sub _num {
	my $number = shift;
	return [
		[1,1,1,1,0,1,1,0,1,1,0,1,1,1,1], # 0
		[0,0,1,0,0,1,0,0,1,0,0,1,0,0,1], # 1
		[1,1,1,0,0,1,1,1,1,1,0,0,1,1,1], # 2
		[1,1,1,0,0,1,1,1,1,0,0,1,1,1,1], # 3
		[1,0,1,1,0,1,1,1,1,0,0,1,0,0,1], # 4
		[1,1,1,1,0,0,1,1,1,0,0,1,1,1,1], # 5
		[1,1,1,1,0,0,1,1,1,1,0,1,1,1,1], # 6
		[1,1,1,0,0,1,0,0,1,0,0,1,0,0,1], # 7
		[1,1,1,1,0,1,1,1,1,1,0,1,1,1,1], # 8
		[1,1,1,1,0,1,1,1,1,0,0,1,1,1,1], # 9
	]->[$number];
}

# Convert number to text.
sub _text {
	my ($char, $number) = @_;
	my $text = '';
	my $num_ar = _num($number);
	foreach my $i (0 .. 14) {
		if ($num_ar->[$i]) {
			$text .= $char x 2;
		} else {
			$text .= '  ';
		}
		if ($i != 14 && ($i + 1) % 3 == 0) {
			$text .= "\n";
		}
	}
	return $text;
}

1;
{'fraction_non_alphanumeric': 0.2888681592039801, 'fraction_numerical': 0.10883084577114428, 'mean_word_length': 3.7800891530460623, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6211318', 'n_tokens_mistral': 1843, 'n_tokens_neox': 1732, 'n_words': 284}