Skip to content

Commit

Permalink
Flipped buyer/seller columns for purchase transactions.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwlManAtt committed Sep 10, 2011
1 parent 93c36d3 commit dc41ada
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
4 changes: 4 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
== 0.9.0 ==
* I am the worst QA engineer in the entire world. Buyer and seller columns
are now correct for purchase transactions.

== 0.8.0 ==
* Initial release. The TSM accounting saved variable file can be transmuted
into a CSV. You can also access its contents in a nice (messy) datastructure.
26 changes: 16 additions & 10 deletions lib/tsm-accounting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
require 'csv'

module TSMAccounting
VERSION = '0.8.0'
VERSION = '0.9.0'

class Database
attr_reader :data
Expand All @@ -42,8 +42,8 @@ def initialize(db_string)
@data[realm_name] = {} unless @data.has_key? realm_name
realm_data.each do |faction_name,faction_data|
@data[realm_name][faction_name] = {} unless @data[realm_name].has_key? faction_name
@data[realm_name][faction_name]['sale'] = parse_rope(faction_data['sell'])
@data[realm_name][faction_name]['purchase'] = parse_rope(faction_data['buy'])
@data[realm_name][faction_name]['sale'] = parse_rope(faction_data['sell'],'sale')
@data[realm_name][faction_name]['purchase'] = parse_rope(faction_data['buy'],'purchase')
end # faction
end # realms
end # initialize
Expand Down Expand Up @@ -163,10 +163,10 @@ def extract_data(db)
return data
end # extract_data

def parse_rope(rope)
def parse_rope(rope,type)
list = {}
rope.split('?').each do |row|
item = Item.new(row)
item = Item.new(row,type)

if list.has_key? item.name
# merge
Expand All @@ -182,15 +182,15 @@ def parse_rope(rope)
class Item
attr_reader :name, :transactions

def initialize(item)
def initialize(item,type)
encoded_item, encoded_records = item.split '!'

if encoded_item[0,1] == 'x'
@name = decode_code(encoded_item)
else
@name = decode_link(encoded_item)
end
@transactions = encoded_records.split('@').map {|record| Transaction.new(record) }
@transactions = encoded_records.split('@').map {|record| Transaction.new(record,type) }
@transactions ||= []
end # initialize

Expand All @@ -214,15 +214,21 @@ def decode_code(text)
class Transaction
attr_reader :stack_size, :quantity, :datetime, :price, :buyer, :seller

def initialize(encoded_string)
def initialize(encoded_string,type)
d = encoded_string.split('#')

@stack_size = decode(d[0])
@quantity = decode(d[1])
@datetime = Time.at(decode(d[2]))
@price = decode(d[3])
@buyer = d[4]
@seller = d[5]

if type == 'purchase'
@buyer = d[5]
@seller = d[4]
else
@buyer = d[4]
@seller = d[5]
end
end # initialize

def usable_price
Expand Down

0 comments on commit dc41ada

Please sign in to comment.