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

46 lines
1.0 KiB
Perl
Raw Normal View History

2013-05-14 10:36:05 -07:00
package DDG::Goodie::Braille;
# ABSTRACT: Braille <-> ASCII/Unicode
2013-05-14 10:36:05 -07:00
use strict;
2013-05-14 10:36:05 -07:00
use DDG::Goodie;
2013-05-14 10:36:05 -07:00
use Convert::Braille;
2014-10-06 11:00:41 -07:00
use utf8;
2013-05-14 10:36:05 -07:00
triggers query_raw => qr/\p{Braille}|( in| to){1} braille$|^braille:/i;
2013-05-14 10:36:05 -07:00
zci is_cached => 1;
2014-10-06 11:00:41 -07:00
my $braille_space = ''; # the braille unicode space (U+2800)
2013-05-14 10:36:05 -07:00
handle query_raw => sub {
2014-10-06 11:00:41 -07:00
my $query = $_;
$query =~ s/( in| to){1} braille$|^braille:\s?//;
2014-10-06 11:00:41 -07:00
return unless $query;
my $response;
my $type;
2014-10-06 11:00:41 -07:00
if ($query =~ /\p{Braille}/) {
$response = join(" ", map { lc(brailleDotsToAscii($_)) } split(/$braille_space/, $query));
$type = "Ascii/Unicode";
2014-10-06 11:00:41 -07:00
} else {
$response = join($braille_space, map { brailleAsciiToUnicode(uc $_) } split(/\s/, $query));
$type = "Braille";
2014-10-06 11:00:41 -07:00
}
return $response,
2014-10-06 11:00:41 -07:00
structured_answer => {
data => {
title => $response,
subtitle => 'Braille translation: ' . html_enc($query),
},
templates => {
group => 'text',
},
2014-10-06 11:00:41 -07:00
};
2013-05-14 10:36:05 -07:00
};
1;