tsm-accounting 1.0.1 → 1.1.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.
- data/HISTORY +5 -0
- data/lib/tsm-accounting.rb +33 -26
- metadata +4 -4
data/HISTORY
CHANGED
data/lib/tsm-accounting.rb
CHANGED
@@ -28,7 +28,7 @@
|
|
28
28
|
require 'csv'
|
29
29
|
|
30
30
|
module TSMAccounting
|
31
|
-
VERSION = '1.0
|
31
|
+
VERSION = '1.1.0'
|
32
32
|
|
33
33
|
class Database
|
34
34
|
class InvalidDatabaseFileException < RuntimeError
|
@@ -53,7 +53,7 @@ module TSMAccounting
|
|
53
53
|
|
54
54
|
def to_csv(output_file)
|
55
55
|
CSV.open(output_file, 'w') do |f|
|
56
|
-
f << ['Realm','Faction','Transaction Type','Time','Item','Quantity','Stack Size','Price (g)','Price (c)','Buyer','Seller']
|
56
|
+
f << ['Realm','Faction','Transaction Type','Time','Item ID','Item Name','Quantity','Stack Size','Price (g)','Price (c)','Buyer','Seller']
|
57
57
|
|
58
58
|
@data.each do |realm,factions|
|
59
59
|
factions.each do |faction,ropes|
|
@@ -62,6 +62,7 @@ module TSMAccounting
|
|
62
62
|
item.transactions.each do |tx|
|
63
63
|
row = [realm,faction,type]
|
64
64
|
row << tx.datetime.strftime('%Y-%m-%d %k:%M:%S')
|
65
|
+
row << item.id
|
65
66
|
row << item.name
|
66
67
|
row << tx.quantity
|
67
68
|
row << tx.stack_size
|
@@ -190,15 +191,15 @@ module TSMAccounting
|
|
190
191
|
end # Database
|
191
192
|
|
192
193
|
class Item
|
193
|
-
attr_reader :name, :transactions
|
194
|
+
attr_reader :id, :name, :transactions
|
194
195
|
|
195
196
|
def initialize(item,type)
|
196
197
|
encoded_item, encoded_records = item.split '!'
|
197
198
|
|
198
199
|
if encoded_item[0,1] == 'x'
|
199
|
-
@name = decode_code(encoded_item)
|
200
|
+
@id, @name = decode_code(encoded_item)
|
200
201
|
else
|
201
|
-
@name = decode_link(encoded_item)
|
202
|
+
@id, @name = decode_link(encoded_item)
|
202
203
|
end
|
203
204
|
@transactions = encoded_records.split('@').map {|record| Transaction.new(record,type) }
|
204
205
|
@transactions ||= []
|
@@ -207,8 +208,14 @@ module TSMAccounting
|
|
207
208
|
protected
|
208
209
|
def decode_link(text)
|
209
210
|
colour, code, name = text.split '|'
|
211
|
+
|
212
|
+
# In the case of items with random enchantments (ie
|
213
|
+
# Jasper Ring of the Bedrock), the item ID is the same for
|
214
|
+
# all rings (52310) but there is an additional attribute
|
215
|
+
# seperated by a colon to identify the enchantment.
|
210
216
|
|
211
|
-
|
217
|
+
id, ench = code.split ':'
|
218
|
+
return [TSMAccounting.decode(id), name]
|
212
219
|
end # decode_link
|
213
220
|
|
214
221
|
# I _think_ this will only get called if the item link cannot
|
@@ -217,7 +224,7 @@ module TSMAccounting
|
|
217
224
|
#
|
218
225
|
# In theory, this shouldn't get called...
|
219
226
|
def decode_code(text)
|
220
|
-
return text
|
227
|
+
return [nil, text]
|
221
228
|
end # decode_string
|
222
229
|
end # item
|
223
230
|
|
@@ -227,10 +234,10 @@ module TSMAccounting
|
|
227
234
|
def initialize(encoded_string,type)
|
228
235
|
d = encoded_string.split('#')
|
229
236
|
|
230
|
-
@stack_size = decode(d[0])
|
231
|
-
@quantity = decode(d[1])
|
232
|
-
@datetime = Time.at(decode(d[2]))
|
233
|
-
@price = decode(d[3])
|
237
|
+
@stack_size = TSMAccounting.decode(d[0])
|
238
|
+
@quantity = TSMAccounting.decode(d[1])
|
239
|
+
@datetime = Time.at(TSMAccounting.decode(d[2]))
|
240
|
+
@price = TSMAccounting.decode(d[3])
|
234
241
|
|
235
242
|
if type == 'purchase'
|
236
243
|
@buyer = d[5]
|
@@ -261,21 +268,21 @@ module TSMAccounting
|
|
261
268
|
return "#{parts['gold']}.#{parts['silver']}".to_f
|
262
269
|
end
|
263
270
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
271
|
+
end # Transaction
|
272
|
+
|
273
|
+
def self.decode(value)
|
274
|
+
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_="
|
275
|
+
base = alpha.length
|
276
|
+
|
277
|
+
i = value.length - 1
|
278
|
+
result = 0
|
279
|
+
value.each_char do |w|
|
280
|
+
if w.match(/([A-Za-z0-9_=])/)
|
281
|
+
result += (alpha.index(w)) * (base**i)
|
282
|
+
i -= 1
|
276
283
|
end
|
284
|
+
end
|
277
285
|
|
278
|
-
|
279
|
-
|
280
|
-
end # Transaction
|
286
|
+
return result
|
287
|
+
end # decode
|
281
288
|
end # TSMAccounting
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tsm-accounting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- owlmanatt
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-09-
|
18
|
+
date: 2011-09-29 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|