diff options
author | Andinus <andinus@nand.sh> | 2020-06-18 05:02:13 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2020-06-18 05:02:13 +0530 |
commit | 5a2c06fbe7a6a70edd02726da17d5fd931eecd8f (patch) | |
tree | 0a2fe67b73297bc839a8942db266a965d5fbfb71 /lib | |
parent | 81d829b1d2a08e3cfbc996caf3e56ddfc9ab2376 (diff) | |
download | ara-5a2c06fbe7a6a70edd02726da17d5fd931eecd8f.tar.gz |
Move state notes table generator to a module
Diffstat (limited to 'lib')
-rw-r--r-- | lib/StateNotes.pm | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/StateNotes.pm b/lib/StateNotes.pm new file mode 100644 index 0000000..9a3cab0 --- /dev/null +++ b/lib/StateNotes.pm @@ -0,0 +1,57 @@ +#!/usr/bin/perl + +package StateNotes; + +use strict; +use warnings; + +use Text::ASCIITable; +use Carp qw( croak carp ); + +sub get { + my ( $statewise, $hide, $show, $rows_to_print ) = @_; + my $table = Text::ASCIITable->new( { drawRowLine => 1 } ); + $table->setCols( qw( State Notes ) ); + $table->setColWidth( 'Notes', 74 ); + + my $rows_in_table = 0; + foreach my $i ( 0 ... scalar @$statewise - 1 ) { + # $rows_printed is incremented at the end of this foreach + # loop. + if ( $rows_to_print ) { + last if $rows_in_table == $rows_to_print; + } + + my $state = $statewise->[$i]{state}; + + # If user has asked to show specific states then forget about + # hide option. + if ( scalar keys %$show ) { + next + unless exists $show->{lc $state} + or ( length $state > 16 + and exists $show->{lc $statewise->[$i]{statecode}}); + } else { + next + if exists $hide->{lc $state} + # User sees the statecode if length $state > 16 so we + # also match against that. + or ( length $state > 16 + and exists $hide->{lc $statewise->[$i]{statecode}}); + } + + $state = $statewise->[$i]{statecode} + if length $state > 16; + + unless ( length($statewise->[$i]{statenotes}) == 0 ) { + $table->addRow( + $state, + $statewise->[$i]{statenotes}, + ) ; + $rows_in_table++; + } + } + return ( $table, $rows_in_table ); +} + +1; |