Book-Collate

 view release on metacpan or  search on metacpan

lib/Book/Collate/Writer/Report.pm  view on Meta::CPAN

package Book::Collate::Writer::Report;

use 5.006;
use strict;
use warnings;

use Book::Collate;

=head1 NAME

Book::Collate::Writer::Report

=head1 VERSION

Version 0.0.1

=cut

our $VERSION = 'v0.0.1';


=head1 SYNOPSIS

Given a file name, a report directory name, and a data object that includes report data,
writes the report.


=head1 EXPORT

A list of functions that can be exported.  You can delete this section
if you don't export anything, such as for a purely object-oriented module.

=head1 SUBROUTINES/METHODS

=head2 _generate_fry_stats

Gives a percentage of Fry list words used against the total unique words used.

=cut

sub _generate_fry_stats {
  my ( $word_list, $custom_word_list ) = @_;
  my %word_list = %{$word_list};
  my %custom_word_list = %{$custom_word_list};
  my %fry_words = %Book::Collate::Words::fry;
  my %used_words;
  my %missed;
  my %fry_used = (
    fry     => 0,
    custom  => 0,
    miss    => 0,
  );
  foreach my $word ( keys %word_list ){
    $word = Book::Collate::Utils::scrub_word($word);
    $used_words{$word} = 1;
  }

  foreach my $word ( keys %used_words ){
    if ( defined($fry_words{$word}) ){
      $fry_used{fry}++;
    } elsif ( defined($custom_word_list{$word}) ){
      $fry_used{custom}++;
    } else {
      $fry_used{miss}++;
      $missed{$word} = 1;
    }
  }
  return %fry_used;
}


=head2 write_fry_stats

Produces a string based on Fry word usage.

=cut

sub write_fry_stats {
  my ( $word_list, $custom_word_list ) = @_;
  my %fry_used  = _generate_fry_stats( $word_list, $custom_word_list );
  my $string    = "Fry Stats:\n";
  $string       .= "  Used   " . $fry_used{fry}     . "\n";
  $string       .= "  Custom " . $fry_used{custom}  . "\n";
  $string       .= "  Miss   " . $fry_used{miss}    . "\n";
  return $string;
}

=head2 write_weak_word_count

Produces a string of weak word usage.

=cut

sub write_weak_word_count {
  my ( $weak_word_used_ref ) = @_;
  my %weak_used = %{$weak_word_used_ref};
  my $string = "Weak Words:\n";



( run in 1.167 second using v1.01-cache-2.11-cpan-99c4e6809bf )