File: | lib/Railsish/TextHelpers.pm |
Coverage: | 85.7% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package Railsish::TextHelpers; | ||||||
2 | 15 15 15 | 147 45 165 | use strict; | ||||
3 | 15 15 15 | 151 43 146 | use warnings; | ||||
4 | 15 15 15 | 129 55 178 | use Exporter::Lite; | ||||
5 | |||||||
6 | our @EXPORT = qw( pluralize singularize camelize camelcase underscore dasherize forien_key ); | ||||||
7 | |||||||
8 | 15 15 15 | 1238 63 200 | use Lingua::EN::Inflect::Number qw(to_S to_PL); | ||||
9 | |||||||
10 | 5 | 0 | 43 | sub pluralize { &to_PL } | |||
11 | 5 | 0 | 34 | sub singularize { &to_S } | |||
12 | |||||||
13 | 15 15 15 | 1370 90 214 | use String::CamelCase qw(camelize decamelize); | ||||
14 | |||||||
15 | 1 | 0 | 7 | sub camelcase { &camelize } | |||
16 | 3 | 0 | 43 | sub underscore { &decamelize } | |||
17 | |||||||
18 | sub dasherize { | ||||||
19 | 1 | 0 | 7 | my $str = &decamelize; | |||
20 | 1 | 31 | $str =~ s/_/-/g; | ||||
21 | 1 | 7 | return $str; | ||||
22 | } | ||||||
23 | |||||||
24 | sub forien_key { | ||||||
25 | 1 | 0 | 6 | my $str = &decamelize; | |||
26 | 1 | 25 | $str =~ s/(?!_id)$/_id/; | ||||
27 | 1 | 8 | return $str; | ||||
28 | } | ||||||
29 | |||||||
30 | 1; | ||||||
31 |