git ssb

0+

cel / ledger-scripts



Commit f357ae91ba3f3d3aa2221475e5eb22e74fbcfb55

Whitespace

Charles Lehner committed on 11/1/2015, 1:50:54 AM
Parent: cc2c8e2f19e9a0b6ebca84a67018e3c2df751517

Files changed

merge-ledgerchanged
merge-ledgerView
@@ -80,9 +80,9 @@
8080 push @$lines, $line;
8181 return $entry if $line =~ /^$/;
8282 # Record item amounts
8383 if ($line =~ /^\s*[^;].*?(?:\s\s|\t)\s*[^@ ]*? ?[^ 0-9]?-?([0-9.,]+)0*[^@]*?\s+(?:;.*|@.*)?$/) {
84- # Account 35.0 BTC @ $15.19
84+ # Account 35.0 BTC @ $15.19
8585 $amounts->{+$1} = 1;
8686 }
8787 }
8888
@@ -92,18 +92,18 @@
9292 sub print_entry {
9393 my ($stream, $entry) = @_;
9494 #$stream //= \*STDOUT;
9595 #print $stream "fh: ".($entry->{fh} // 'null').". i: ".$entry->{buffer_i}."\n";
96- print "amounts: ";
97- print $_ . ", " for keys($entry->{amounts});
98- print "\n";
96+ print "amounts: ";
97+ print $_ . ", " for keys($entry->{amounts});
98+ print "\n";
9999 print $stream $_ for @{ $entry->{lines} };
100100 }
101101
102102 sub get_oldest_entry {
103103 return unless scalar @buffer;
104104
105- # pick the oldest entry
105+ # pick the oldest entry
106106 my $oldest = shift @buffer;
107107 for my $entry (@buffer) {
108108 if ($entry->{date} < $oldest->{date}) {
109109 $oldest = $entry;
@@ -114,18 +114,18 @@
114114 }
115115
116116 sub entry_matches_date {
117117 my ($entry, $date) = @_;
118- my $diff = $date - $entry->{date};
118+ my $diff = $date - $entry->{date};
119119 printf("%s, %s: %s days\n", $date, $entry->{date}, $diff);
120- return (abs(int($diff->days)) < $time_difference);
120+ return (abs(int($diff->days)) < $time_difference);
121121 }
122122
123123 sub entry_matches_amounts {
124124 my ($entry, $amounts) = @_;
125- # require at least half of the amounts from entry to be present in amounts
126- my @amounts2 = keys $entry->{amounts};
127- my $matched = 0;
125+ # require at least half of the amounts from entry to be present in amounts
126+ my @amounts2 = keys $entry->{amounts};
127+ my $matched = 0;
128128 for my $amt (@amounts2) {
129129 $matched++ if $amounts->{$amt};
130130 }
131131 return ($matched / scalar @amounts2) >= 0.5;
@@ -138,13 +138,13 @@
138138 my $fh = $entry->{fh};
139139 my @matches = grep {
140140 defined $_ and
141141 $fh != $_->{fh} and
142- #entry_matches_date($_, $date) and
142+ #entry_matches_date($_, $date) and
143143 entry_matches_amounts($_, $amounts)
144144 } @buffer;
145- # append original entry
146- unshift @matches, $entry if (scalar @matches);
145+ # append original entry
146+ unshift @matches, $entry if (scalar @matches);
147147 return @matches;
148148 }
149149
150150 sub merge_edit_entries {
@@ -193,17 +193,17 @@
193193 }
194194
195195 sub replace_entry {
196196 my $entry = shift;
197- return unless $entry;
197+ return unless $entry;
198198
199- # remove this entry from the buffer
200- @buffer = grep { $_ != $entry } @buffer;
199+ # remove this entry from the buffer
200+ @buffer = grep { $_ != $entry } @buffer;
201201
202202 # Read a new entry and add it to the buffer
203203 my $fh = $entry->{fh};
204204 if (my $new_entry = read_entry $fh) {
205- push @buffer, $new_entry;
205+ push @buffer, $new_entry;
206206 }
207207 }
208208
209209 # Open the ledger journals
@@ -236,10 +236,10 @@
236236 # user kept the entries seperate.
237237 # Print the single entry and leave the others in their buffers
238238 print_entry \*OUTFILE, $entry;
239239
240- # replace this entry in the buffer with a new one
241- replace_entry($entry);
240+ # replace this entry in the buffer with a new one
241+ replace_entry($entry);
242242 }
243243 } else {
244244 # No matching entries.
245245 # Print the entry

Built with git-ssb-web