This repository has been archived by the owner on Oct 15, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1132903
commit 979e629
Showing
2 changed files
with
1,906 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,62 @@ | |||
package DDG::Goodie::Dewey; | |||
# ABSTRACT: Identify and find dewey decimal system numbers | |||
|
|||
use DDG::Goodie; | |||
|
|||
triggers startend => 'dewey'; | |||
|
|||
zci answer_type => 'dewey_decimal'; | |||
|
|||
zci is_cached => 1; | |||
|
|||
attribution | |||
twitter => 'crazedpsyc', | |||
cpan => 'CRZEDPSYC' | |||
; | |||
|
|||
my %nums = share('dewey.txt')->slurp; | |||
#my %types = reverse %nums; | |||
|
|||
sub get_info { | |||
my($num) = @_; | |||
$num = "0" x (3-length($num)) . $num; | |||
my $desc = $nums{"$_\n"} or return; | |||
chomp $desc; | |||
return $desc; | |||
} | |||
|
|||
sub line { | |||
my($num) = @_; | |||
return "<td>$num</td><td>".(get_info($num) or return)."</td>"; | |||
} | |||
|
|||
handle remainder => sub { | |||
return unless s/^(?:decimal)?\s*(?:system)?\s*(\d{3})(?:\.\d+)?(s)?\s*(?:decimal)?\s*(?:system)?$/$1/; | |||
my ($out_html, $out) = ("",""); | |||
|
|||
my $multi = $2; | |||
|
|||
unless ($multi) { | |||
$out .= "$_ is " . lc((get_info($_) or return)); | |||
$out .= " in the Dewey Decimal System"; | |||
$out_html = $out; | |||
} | |||
elsif (/\d00/) { | |||
for ($_..$_+99) { | |||
$out_html .= "<tr>" .(line($_) or next). "</tr>"; | |||
} | |||
} | |||
elsif (/\d\d0/) { | |||
for ($_..$_+10) { | |||
$out_html .= "<tr>" .(line($_) or next). "</tr>"; | |||
} | |||
} | |||
|
|||
$out_html =~ s/\[\[(.+?)\|(.+?)\]\]/<a href="\/\?q=$1">$2<\/a>/g; | |||
$out_html =~ s/\[\[(.+?)\]\]/<a href="$1">$1<\/a>/g; | |||
$out =~ s/\[\[.+?\|(.+?)\]\]/$1/g; | |||
$out =~ s/\[\[(.+?)\]\]/$1/g; | |||
return $multi ? "" : $out, html => $multi ? "<table>$out_html</table>" : $out_html; | |||
}; | |||
|
|||
1; |
Oops, something went wrong.