/[Search-Estraier]/trunk/Estraier.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/Estraier.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 12 by dpavlin, Wed Jan 4 19:28:30 2006 UTC revision 14 by dpavlin, Wed Jan 4 21:51:01 2006 UTC
# Line 47  use Carp qw/croak confess/; Line 47  use Carp qw/croak confess/;
47    
48  =head1 Search::Estraier::Document  =head1 Search::Estraier::Document
49    
50    This class implements Document which is collection of attributes
51    (key=value), vectors (also key value) display text and hidden text.
52    
53  Document for HyperEstraier  Document for HyperEstraier
54    
55  =head2 new  =head2 new
56    
57    Create new document, empty or from draft.
58    
59    my $doc = new Search::HyperEstraier::Document;    my $doc = new Search::HyperEstraier::Document;
60      my $doc2 = new Search::HyperEstraier::Document( $draft );
61    
62  =cut  =cut
63    
64  sub new {  sub new {
65          my $class = shift;          my $class = shift;
66          my $self = {@_};          my $self = {};
67          bless($self, $class);          bless($self, $class);
68    
69          $self->{id} = -1;          $self->{id} = -1;
70    
71            my $draft = shift;
72    
73            if ($draft) {
74                    my $in_text = 0;
75                    foreach my $line (split(/\n/, $draft)) {
76    
77                            if ($in_text) {
78                                    if ($line =~ /^\t/) {
79                                            push @{ $self->{htexts} }, substr($line, 1);
80                                    } else {
81                                            push @{ $self->{dtexts} }, $line;
82                                    }
83                                    next;
84                            }
85    
86                            if ($line =~ m/^%VECTOR\t(.+)$/) {
87                                    my @fields = split(/\t/, $1);
88                                    for my $i ( 0 .. ($#fields - 1) ) {
89                                            $self->{kwords}->{ $fields[ $i ] } = $fields[ $i + 1 ];
90                                            $i++;
91                                    }
92                                    next;
93                            } elsif ($line =~ m/^%/) {
94                                    # What is this? comment?
95                                    #warn "$line\n";
96                                    next;
97                            } elsif ($line =~ m/^$/) {
98                                    $in_text = 1;
99                                    next;
100                            } elsif ($line =~ m/^(.+)=(.+)$/) {
101                                    $self->{attrs}->{ $1 } = $2;
102                                    next;
103                            }
104    
105                            warn "draft ignored: $line\n";
106                    }
107            }
108    
109          $self ? return $self : return undef;          $self ? return $self : return undef;
110  }  }
111    
# Line 200  sub cat_texts { Line 244  sub cat_texts {
244    
245  =head2 dump_draft  =head2 dump_draft
246    
247    Dump draft data from document object.
248    
249    print $doc->dump_draft;    print $doc->dump_draft;
250    
251  =cut  =cut
252    
253  sub dump_draft {  sub dump_draft {
254          return 'FIXME';          my $self = shift;
255            my $draft;
256    
257            foreach my $attr_name (sort keys %{ $self->{attrs} }) {
258                    $draft .= $attr_name . '=' . $self->{attrs}->{$attr_name} . "\n";
259            }
260    
261            if ($self->{kwords}) {
262                    $draft .= '%%VECTOR';
263                    while (my ($key, $value) = each %{ $self->{kwords} }) {
264                            $draft .= "\t$key\t$value";
265                    }
266                    $draft .= "\n";
267            }
268    
269            $draft .= "\n";
270    
271            $draft .= join("\n", @{ $self->{dtexts} }) . "\n";
272            $draft .= "\t" . join("\n\t", @{ $self->{htexts} }) . "\n";
273    
274            return $draft;
275  }  }
276    
277  =head2 delete  =head2 delete
# Line 219  Empty document object Line 285  Empty document object
285  sub delete {  sub delete {
286          my $self = shift;          my $self = shift;
287    
288          foreach my $data (qw/attrs dtexts stexts/) {          foreach my $data (qw/attrs dtexts stexts kwords/) {
289                  delete($self->{$data});                  delete($self->{$data});
290          }          }
291    

Legend:
Removed from v.12  
changed lines
  Added in v.14

  ViewVC Help
Powered by ViewVC 1.1.26