Skip to content

Commit

Permalink
bugfix is_drama for NANP
Browse files Browse the repository at this point in the history
  • Loading branch information
DrHyde committed Oct 11, 2016
1 parent 5c05006 commit fc65d76
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
19 changes: 12 additions & 7 deletions lib/Number/Phone/NANP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,6 @@ that if we can.
NANP-globals are fixed lines, for the rest we generally don't know with some
exceptions as per is_mobile above.
=item is_drama
The number is a '555' number. Numbers with the D, E, and F digits set to 555
are not allocated to real customers, and are intended for use in fiction. eg
212 555 2368 for Ghostbusters.
=cut

# See Message-ID: <008001c406ba$6bd01820$dad4a645@anhmca.adelphia.net>
Expand Down Expand Up @@ -185,9 +179,20 @@ sub is_fixed_line {
return ${$self} =~ /^\+1($Number::Phone::NANP::Data::fixed_line_regexes{$ISO_country_code})$/ ? 1 : 0;
}

=item is_drama
The number is a '555' number. Numbers with the D, E, and F digits set to 555
are not allocated to real customers, and are intended for use in fiction. eg
212 555 2368 for Ghostbusters.
NB, despite Ghostbusters above, only 555-0100 to 555-0199 are actually reserved.
=cut

sub is_drama {
my $self = shift;
return ${$self} =~ /555\d{4}$/ ? 1 : 0;
${$self} =~ /(555)(\d{4})$/;
return ($1 eq '555' && $2 gt '0099' && $2 lt '0200') ? 1 : 0;
}

sub areaname {
Expand Down
4 changes: 3 additions & 1 deletion t/inc/common-nanp_and_libphonenumber_tests.pl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@

note("is_drama");
skip_if_libphonenumber("Stubs don't support is_drama", 2, sub {
is($CLASS->new('+12125552368')->is_drama(), 1, "Ghostbusters have an is_drama number");
is($CLASS->new('+12125552368')->is_drama(), 0, "Ghostbusters isn't is_drama (last four digits too high)");
is($CLASS->new('+12125550001')->is_drama(), 0, "555-0001 isn't is_drama (last four digits too low)");
is($CLASS->new('+12125550123')->is_drama(), 1, "555-0123 is is_drama (last four digits just right, like porridge)");
is($CLASS->new('+12024566213')->is_drama(), 0, "The president doesn't have an is_drama number");
});

Expand Down

0 comments on commit fc65d76

Please sign in to comment.