moneybook 0.2.6 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/bin/moneybook +55 -0
  3. data/moneybook.gemspec +2 -2
  4. metadata +5 -5
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.6
1
+ 0.3.0
@@ -118,6 +118,59 @@ def get_final(sq, people)
118
118
  [final, spent, given, debt]
119
119
  end
120
120
 
121
+ def get_exchanges(final,people)
122
+ poor_p = [] # people who must give..
123
+ poor_v = []
124
+ rich_p = [] # people who shall receive..
125
+ rich_v = []
126
+ final[0].each_pair{|person, value|
127
+ if value > 0 then
128
+ rich_p << person
129
+ rich_v << value.round
130
+ elsif value < 0 then
131
+ poor_p << person
132
+ poor_v << -value.round
133
+ else
134
+ # this person doesn't have to give or receive anything..
135
+ end
136
+ }
137
+ puts "\nPOSSIBLE (APPROX) EXCHANGES.."
138
+ while (eq=rich_v-(rich_v-poor_v)) != [] do
139
+ receives = rich_v.index eq[0]
140
+ gives = poor_v.index eq[0]
141
+ amount = eq[0]
142
+ puts "#{poor_p[gives]} gives #{amount} to #{rich_p[receives]}"
143
+ rich_p.delete_at receives
144
+ rich_v.delete_at receives
145
+ poor_p.delete_at gives
146
+ poor_v.delete_at gives
147
+ end
148
+ timeout = 20
149
+ while poor_v.length > 0 && rich_v.length > 0 && timeout > 0 do
150
+ #pp "---"
151
+ #pp [poor_v, rich_v]
152
+ #pp [poor_p, rich_p]
153
+ gives = poor_v.index poor_v.max
154
+ receives = rich_v.index rich_v.min
155
+ amount = poor_v.max >= rich_v.min ? rich_v.min : poor_v.max
156
+ puts "#{poor_p[gives]} gives #{amount} to #{rich_p[receives]}"
157
+ rich_v[receives] -= amount
158
+ poor_v[gives] -= amount
159
+ #pp [poor_v, rich_v]
160
+ #pp [poor_p, rich_p]
161
+ if poor_v[gives] == 0
162
+ poor_p.delete_at gives
163
+ poor_v.delete_at gives
164
+ end
165
+ if rich_v[receives] == 0
166
+ rich_p.delete_at receives
167
+ rich_v.delete_at receives
168
+ end
169
+ timeout -= 1
170
+ end
171
+ puts "--------------"
172
+ end
173
+
121
174
  def command_parse(options, filename)
122
175
  intermediate = options[:intermediate]
123
176
  people = []
@@ -276,6 +329,8 @@ def command_parse(options, filename)
276
329
  person = people[i]
277
330
  puts "#{people_to_print[i]} #{final[0][person] == 0 ? '--- ' : (final[0][person] > 0 ? 'receives' : 'gives ')} #{"% 8.2f" % (final[0][person]*currency_change)} spent #{"% 8.2f" % (final[1][person]*currency_change)} given #{"% 8.2f" % (final[2][person]*currency_change)} debt #{"% 8.2f" % final[3][person]*currency_change}" if currency_change > 0
278
331
  }
332
+ ### PRINT MONEY EXCHANGES ###
333
+ exchanges = get_exchanges(final,people)
279
334
  end
280
335
 
281
336
  process_command(ARGV)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{moneybook}
8
- s.version = "0.2.4"
8
+ s.version = "0.2.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["luca cioria"]
12
- s.date = %q{2011-02-21}
12
+ s.date = %q{2011-02-23}
13
13
  s.default_executable = %q{moneybook}
14
14
  s.description = %q{keep track of money in a group}
15
15
  s.email = %q{noreply@mail.com}
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moneybook
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 6
10
- version: 0.2.6
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - luca cioria
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-23 00:00:00 +01:00
18
+ date: 2011-03-02 00:00:00 +01:00
19
19
  default_executable: moneybook
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency