Skip to content
Browse files

Add Hebrew character set and flesh out enumerator

  • Loading branch information...
1 parent e83f10e commit b66519ee5a412ef1ba3ef3e5d61a41dace9eb001 @ctfliblime committed Mar 20, 2012
Showing with 44 additions and 11 deletions.
  1. +27 −4 lib/Xape/Charset/he.pm
  2. +5 −2 lib/Xape/Enumerator.pm
  3. +12 −5 t/001-enum.t
View
31 lib/Xape/Charset/he.pm
@@ -1,16 +1,39 @@
package Xape::Charset::he;
use Any::Moose;
-use utf8;
has 'charmap' => (
is => 'ro',
isa => 'HashRef',
default => sub {
return {
- a => 'A',
- b => 'B',
- c => 'C',
+ "\x{5d0}" => 1,
+ "\x{5d1}" => 2,
+ "\x{5d2}" => 3,
+ "\x{5d3}" => 4,
+ "\x{5d4}" => 5,
+ "\x{5d5}" => 6,
+ "\x{5d6}" => 7,
+ "\x{5d7}" => 8,
+ "\x{5d8}" => 9,
+ "\x{5d9}" => 10,
+ "\x{5da}" => 20,
+ "\x{5db}" => 20,
+ "\x{5dc}" => 30,
+ "\x{5dd}" => 40,
+ "\x{5de}" => 40,
+ "\x{5df}" => 50,
+ "\x{5e0}" => 50,
+ "\x{5e1}" => 60,
+ "\x{5e2}" => 70,
+ "\x{5e3}" => 80,
+ "\x{5e4}" => 80,
+ "\x{5e5}" => 90,
+ "\x{5e6}" => 90,
+ "\x{5e7}" => 100,
+ "\x{5e8}" => 200,
+ "\x{5e9}" => 300,
+ "\x{5ea}" => 400,
};
},
);
View
7 lib/Xape/Enumerator.pm
@@ -33,8 +33,11 @@ around BUILDARGS => sub {
}
};
-method enumerate(Str $input) {
- return undef;
+method sum(Str $input) {
+ my @chars = split '', $input;
+ my $sum = 0;
+ $sum += $self->charset->lookup($_) // 0 for (@chars);
+ return $sum;
}
__PACKAGE__->meta->make_immutable;
View
17 t/001-enum.t
@@ -2,6 +2,9 @@
use strict;
use warnings;
+use utf8;
+binmode(STDOUT, ':utf8');
+
use Test::More;
BEGIN {
@@ -12,10 +15,10 @@ BEGIN {
my $charset = Xape::Charset::he->new();
isa_ok $charset, 'Xape::Charset::he';
-is $charset->lookup('a'), 'A';
-is $charset->lookup('b'), 'B';
-isnt $charset->lookup('a'), 'B';
-isnt $charset->lookup('A'), 'a';
+is $charset->lookup("\x{5d0}"), 1;
+is $charset->lookup("\x{5da}"), 20;
+is $charset->lookup("\x{5db}"), 20;
+is $charset->lookup("\x{5ea}"), 400;
my $enum;
$enum = Xape::Enumerator->new(charset => $charset);
@@ -27,6 +30,10 @@ isa_ok $enum, 'Xape::Enumerator';
$enum = Xape::Enumerator->new('he');
isa_ok $enum, 'Xape::Enumerator';
-can_ok $enum, qw(enumerate);
+can_ok $enum, qw(sum);
+
+is $enum->sum("\x{5d0}"), 1, 'Single sum';
+is $enum->sum("\x{5d0}\x{5ea}"), 401, 'Multiple sum';
+is $enum->sum("\x{5d0} \x{5ea} \x{5da}"), 421, 'Ignore space';
done_testing;

0 comments on commit b66519e

Please sign in to comment.
Something went wrong with that request. Please try again.