zeroclickinfo-goodies/lib/DDG/Goodie/Paper.pm

44 lines
1.2 KiB
Perl
Raw Normal View History

2013-02-09 10:49:22 -08:00
package DDG::Goodie::Paper;
2014-06-30 18:24:26 -07:00
# ABSTRACT: Return the dimensions of a defined paper size
2013-02-09 10:49:22 -08:00
use strict;
2013-02-09 10:49:22 -08:00
use DDG::Goodie;
2015-05-29 15:18:03 -07:00
use YAML::XS 'LoadFile';
2013-02-09 10:49:22 -08:00
2014-06-30 18:24:26 -07:00
zci answer_type => "paper";
zci is_cached => 1;
triggers any => 'paper size', 'dimensions', 'paper dimension', 'paper dimensions';
primary_example_queries 'letter paper size';
secondary_example_queries 'a1 paper size', 'a9 paper dimension';
description 'Lookup the size of standard paper sizes';
name 'Paper';
code_url
'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/Paper.pm';
category 'conversions';
topics 'special_interest';
attribution github => ['loganom', 'Logan McCamon'],
twitter => ['loganmccamon', 'Logan McCamon'],
github => ['mattlehnig', 'Matt Lehnig'];
2014-06-30 18:24:26 -07:00
2015-05-29 15:18:03 -07:00
my $sizes = LoadFile(share('sizes.yml'));
2013-02-09 10:49:22 -08:00
handle query_lc => sub {
return unless my ($s, $l, $n) = $_ =~ /^((?:(a|b|c)(\d{0,2}))|legal|letter|junior\s*legal|ledger|tabloid|hagaki)\s+paper\s+(?:size|dimm?ensions?)$/i;
2013-02-09 10:49:22 -08:00
2014-10-14 11:39:20 -07:00
my $value = $sizes->{$s};
return unless $value;
2013-02-09 10:49:22 -08:00
2014-10-14 11:39:20 -07:00
$s = uc $s if defined $n;
2013-02-09 10:49:22 -08:00
2014-10-14 11:39:20 -07:00
return $value,
structured_answer => {
input => [$s],
operation => 'Paper size',
2014-10-14 11:39:20 -07:00
result => $value
};
2013-02-09 10:49:22 -08:00
};
1;