Skip to content

Commit

Permalink
clean_show_name method
Browse files Browse the repository at this point in the history
Added method and test cases
  • Loading branch information
Bas-Man committed Apr 13, 2019
1 parent 922094c commit e31cd08
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/File/TVShow/Info.pm
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,28 @@ sub strip_show_name {

}

=head2 clean_show_name
Return complete show name with year and country in brackets if they exist.
Also remove any delimiters, replaced with spaces
=cut

sub clean_show_name {

my $self = shift;

return if !$self->is_tv_show();

my $newString = $self->strip_show_name();
if ($self->has_year()) {
$newString .= ' (' . $self->year() . ')';
} elsif ($self->has_country()) {
$newString .= ' (' . $self->country() . ')';
}
return $newString;
}

=head2 original_show_name
Return the original show name.
Expand Down Expand Up @@ -782,6 +804,8 @@ sub _get_country {
# country strings. If not, we do not set {country}
if (grep { $_ eq $1 } @{$self->{valid_countries}}) {
$self->{country} = $+{country} || $1; # $1 equals group country
$self->{show_name} =~ s/\(?$1\)?//;
chop($self->{show_name});
}
}
}
Expand Down
59 changes: 59 additions & 0 deletions t/13-clean_show_name.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!perl -T
use 5.006;
use strict;
use warnings;
use Test::More;
use Data::Dumper;

unless ( $ENV{DEV_TESTING} ) {
plan( skip_all => "Author tests not required for installation" );
} else {
use File::TVShow::Info;
}

subtest "Prey.S05E03.Pilot.720p.AMZN.WEB-DL.DDP5.1.H.264-NTb[eztv].mkv" => sub {
my $obj = File::TVShow::Info->new("Prey.S05E03.Pilot.720p.AMZN.WEB-DL.DDP5.1.H.264-NTb[eztv].mkv");
is($obj->clean_show_name(), "Prey", "Show Name: Prey");
};

subtest "Prey US.S05E03.Pilot.720p.AMZN.WEB-DL.DDP5.1.H.264-NTb[eztv].mkv" => sub {
my $obj = File::TVShow::Info->new("Prey US.S05E03.Pilot.720p.AMZN.WEB-DL.DDP5.1.H.264-NTb[eztv].mkv");
is($obj->clean_show_name(), "Prey (US)", "Show Name: Prey (US)");
};

subtest "Prey.US.S05E03.Pilot.720p.AMZN.WEB-DL.DDP5.1.H.264-NTb[eztv].mkv" => sub {
my $obj = File::TVShow::Info->new("Prey.US.S05E03.Pilot.720p.AMZN.WEB-DL.DDP5.1.H.264-NTb[eztv].mkv");
is($obj->clean_show_name(), "Prey (US)", "Show Name: Prey (US)");
};

subtest "Prey (US).S05E03.Pilot.720p.AMZN.WEB-DL.DDP5.1.H.264-NTb[eztv].mkv" => sub {
my $obj = File::TVShow::Info->new("Prey (US).S05E03.Pilot.720p.AMZN.WEB-DL.DDP5.1.H.264-NTb[eztv].mkv");
is($obj->clean_show_name(), "Prey (US)", "Show Name: Prey (US)");
};

subtest "Prey.(US).S05E03.Pilot.720p.AMZN.WEB-DL.DDP5.1.H.264-NTb[eztv].mkv" => sub {
my $obj = File::TVShow::Info->new("Prey.(US).S05E03.Pilot.720p.AMZN.WEB-DL.DDP5.1.H.264-NTb[eztv].mkv");
is($obj->clean_show_name(), "Prey (US)", "Show Name: Prey (US)");
};

subtest "Castle.S05E03.Pilot.720p.AMZN.WEB-DL.DDP5.1.H.264-NTb[eztv].mkv" => sub {
my $obj = File::TVShow::Info->new("Castle.S05E03.Pilot.720p.AMZN.WEB-DL.DDP5.1.H.264-NTb[eztv].mkv");
is($obj->clean_show_name(), "Castle", "Show Name: Castle");
};

subtest "Castle.2009.S05E03.Pilot.720p.AMZN.WEB-DL.DDP5.1.H.264-NTb[eztv].mkv" => sub {
my $obj = File::TVShow::Info->new("Castle.2009.S05E03.Pilot.720p.AMZN.WEB-DL.DDP5.1.H.264-NTb[eztv].mkv");
is($obj->clean_show_name(), "Castle (2009)", "Show Name: Castle (2009)");
};

subtest "Castle.(2009).S05E03.Pilot.720p.AMZN.WEB-DL.DDP5.1.H.264-NTb[eztv].mkv" => sub {
my $obj = File::TVShow::Info->new("Castle.(2009).S05E03.Pilot.720p.AMZN.WEB-DL.DDP5.1.H.264-NTb[eztv].mkv");
is($obj->clean_show_name(), "Castle (2009)", "Show Name: Castle (2009)");
};

subtest "Doctor.Who.(2005).S05E03.Pilot.720p.AMZN.WEB-DL.DDP5.1.H.264-NTb[eztv].mkv" => sub {
my $obj = File::TVShow::Info->new("Doctor.Who.(2005).S05E03.Pilot.720p.AMZN.WEB-DL.DDP5.1.H.264-NTb[eztv].mkv");
is($obj->clean_show_name(), "Doctor Who (2005)", "Show Name: Doctor Who (2009)");
};

done_testing();

0 comments on commit e31cd08

Please sign in to comment.