Commit f357ae91ba3f3d3aa2221475e5eb22e74fbcfb55
Whitespace
Charles Lehner committed on 11/1/2015, 1:50:54 AMParent: cc2c8e2f19e9a0b6ebca84a67018e3c2df751517
Files changed
merge-ledger | changed |
merge-ledger | ||
---|---|---|
@@ -80,9 +80,9 @@ | ||
80 | 80 | push @$lines, $line; |
81 | 81 | return $entry if $line =~ /^$/; |
82 | 82 | # Record item amounts |
83 | 83 | 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 | |
85 | 85 | $amounts->{+$1} = 1; |
86 | 86 | } |
87 | 87 | } |
88 | 88 | |
@@ -92,18 +92,18 @@ | ||
92 | 92 | sub print_entry { |
93 | 93 | my ($stream, $entry) = @_; |
94 | 94 | #$stream //= \*STDOUT; |
95 | 95 | #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"; | |
99 | 99 | print $stream $_ for @{ $entry->{lines} }; |
100 | 100 | } |
101 | 101 | |
102 | 102 | sub get_oldest_entry { |
103 | 103 | return unless scalar @buffer; |
104 | 104 | |
105 | - # pick the oldest entry | |
105 | + # pick the oldest entry | |
106 | 106 | my $oldest = shift @buffer; |
107 | 107 | for my $entry (@buffer) { |
108 | 108 | if ($entry->{date} < $oldest->{date}) { |
109 | 109 | $oldest = $entry; |
@@ -114,18 +114,18 @@ | ||
114 | 114 | } |
115 | 115 | |
116 | 116 | sub entry_matches_date { |
117 | 117 | my ($entry, $date) = @_; |
118 | - my $diff = $date - $entry->{date}; | |
118 | + my $diff = $date - $entry->{date}; | |
119 | 119 | 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); | |
121 | 121 | } |
122 | 122 | |
123 | 123 | sub entry_matches_amounts { |
124 | 124 | 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; | |
128 | 128 | for my $amt (@amounts2) { |
129 | 129 | $matched++ if $amounts->{$amt}; |
130 | 130 | } |
131 | 131 | return ($matched / scalar @amounts2) >= 0.5; |
@@ -138,13 +138,13 @@ | ||
138 | 138 | my $fh = $entry->{fh}; |
139 | 139 | my @matches = grep { |
140 | 140 | defined $_ and |
141 | 141 | $fh != $_->{fh} and |
142 | - #entry_matches_date($_, $date) and | |
142 | + #entry_matches_date($_, $date) and | |
143 | 143 | entry_matches_amounts($_, $amounts) |
144 | 144 | } @buffer; |
145 | - # append original entry | |
146 | - unshift @matches, $entry if (scalar @matches); | |
145 | + # append original entry | |
146 | + unshift @matches, $entry if (scalar @matches); | |
147 | 147 | return @matches; |
148 | 148 | } |
149 | 149 | |
150 | 150 | sub merge_edit_entries { |
@@ -193,17 +193,17 @@ | ||
193 | 193 | } |
194 | 194 | |
195 | 195 | sub replace_entry { |
196 | 196 | my $entry = shift; |
197 | - return unless $entry; | |
197 | + return unless $entry; | |
198 | 198 | |
199 | - # remove this entry from the buffer | |
200 | - @buffer = grep { $_ != $entry } @buffer; | |
199 | + # remove this entry from the buffer | |
200 | + @buffer = grep { $_ != $entry } @buffer; | |
201 | 201 | |
202 | 202 | # Read a new entry and add it to the buffer |
203 | 203 | my $fh = $entry->{fh}; |
204 | 204 | if (my $new_entry = read_entry $fh) { |
205 | - push @buffer, $new_entry; | |
205 | + push @buffer, $new_entry; | |
206 | 206 | } |
207 | 207 | } |
208 | 208 | |
209 | 209 | # Open the ledger journals |
@@ -236,10 +236,10 @@ | ||
236 | 236 | # user kept the entries seperate. |
237 | 237 | # Print the single entry and leave the others in their buffers |
238 | 238 | print_entry \*OUTFILE, $entry; |
239 | 239 | |
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); | |
242 | 242 | } |
243 | 243 | } else { |
244 | 244 | # No matching entries. |
245 | 245 | # Print the entry |
Built with git-ssb-web