forked from paxed/Rodney
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathignorance.pm
More file actions
92 lines (74 loc) · 1.67 KB
/
ignorance.pm
File metadata and controls
92 lines (74 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package Ignorance;
use strict;
use warnings;
use diagnostics;
use DBI;
do "librodney.pm";
sub new {
my $class = shift;
my %args = @_;
return bless \%args, $class;
}
# $self->init(FILENAME);
sub init {
my $self = shift;
my $seenfile = shift || $self->{'dbfile'};
$self->{'dbfile'} = $seenfile if (!$self->{'dbfile'});
@{$self->{'ignorance'}} = ();
}
sub is_ignored {
my $self = shift;
my $who = shift;
my $line = shift;
foreach my $a (@{$self->{'ignorance'}}) {
my @b = ( split /\t/, $a );
return 1 if (($who =~ m/\l$b[0]\Q/i) && ($line =~ m/\l$b[1]\Q/i));
}
return 0;
}
sub count {
my $self = shift;
my $len = @{$self->{'ignorance'}};
return int($len);
}
sub get_nth {
my $self = shift;
my $n = shift || 0;
return @{$self->{'ignorance'}}[$n] if ($n >= 0 && $n < scalar(@{$self->{'ignorance'}}));
return '';
}
sub rm_nth {
my $self = shift;
my $n = shift || 0;
splice(@{$self->{'ignorance'}}, $n, 1) if ($n >= 0 && $n < scalar(@{$self->{'ignorance'}}));
}
sub add {
my $self = shift;
my $a = shift || "";
push(@{$self->{'ignorance'}}, $a) if ($a =~ m/\t/);
}
sub save {
my $self = shift;
my $fname = $self->{'dbfile'};
open(IGNWRITE, ">", $fname) || return;
foreach my $a (@{$self->{'ignorance'}}) {
print IGNWRITE "$a\n";
}
close(IGNWRITE);
}
sub load {
my $self = shift;
my $fname = $self->{'dbfile'};
if (open(IGNREAD, $fname)) {
@{$self->{'ignorance'}} = ();
while (<IGNREAD>) {
my $a = $_;
chop($a);
push(@{$self->{'ignorance'}}, $a) if ($a =~ m/^(.+)\t(.+)$/);
}
} else {
debugprint("can't read $fname");
}
}
1;
__END__