Changeset 7116 for lang

Show
Ignore:
Timestamp:
02/25/08 11:36:20 (6 years ago)
Author:
nyarla
Message:

lang/perl/Data-Cloud: I implemented filter method.

Location:
lang/perl/Data-Cloud/trunk
Files:
1 added
1 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Data-Cloud/trunk/lib/Data/Cloud.pm

    r4060 r7116  
    99 
    1010sub new { 
    11     my ( $class, @args ) = @_; 
     11    my ( $class, %args ) = @_; 
     12 
     13    my $cs = delete $args{'case_sensitive'}          || 0; 
     14    my $nn = delete $args{'allow_negative_number'}   || 0; 
    1215 
    1316    my $self = bless { 
    14         data => {}, 
     17        data    => {}, 
     18        cs      => $cs, 
     19        nn      => $nn, 
    1520    }, $class; 
    1621 
     
    1924 
    2025sub data { shift->{'data'} } 
     26 
     27sub filter { 
     28    my ( $self, $word, $number ) = @_; 
     29 
     30    if ( ! $self->{'cs'} ) { 
     31        $word = lc $word; 
     32    } 
     33 
     34    if ( ! $self->{'nn'} ) { 
     35        $number = ( $number < 0 ) 
     36                ? 0 
     37                : $number 
     38                ; 
     39    } 
     40 
     41    return ( $word, $number ); 
     42} 
    2143 
    22441; 
     
    4769=head2 new 
    4870 
    49   my $cloud = Data::Cloud->new; 
     71  my $cloud = Data::Cloud->new( %options ); 
     72 
     73This method is constructor of Data::Cloud. 
     74 
     75The following option can be specified as arguments. 
     76 
     77=over 
     78 
     79=item C<'case_sensitive'> 
     80 
     81If this option is true, Data::Cloud distinguishes between uppercase and lowercase letters. 
     82And if this option is false, Data::Cloud does not distinguish between uppercase and lowercase letters. 
     83 
     84This option is false by default. 
     85 
     86=item C<'allow_negative_number'> 
     87 
     88If this option is true, Data::Cloud permits the negative number. 
     89And if this option is fase, Data::Cloud does not permits the negative number. 
     90 
     91This option is false by default. 
     92 
     93=back 
    5094 
    5195=head2 set 
     
    81125  my $count = $cloud->count($word); 
    82126 
     127=head2 filter 
     128 
     129  my ( $word, $number ) = $cloud->filter( $word => $number ); 
     130 
     131This method processes a word and its number with constructor's options. 
     132 
     133When Data::Cloud operates a word and the number, this method is called certainly. 
     134 
    83135=head2 data 
    84136