Class: TSMAccounting::Database
- Inherits:
-
Object
- Object
- TSMAccounting::Database
- Defined in:
- lib/tsm-accounting.rb
Defined Under Namespace
Classes: InvalidDatabaseFileException
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
-
#initialize(db_string) ⇒ Database
constructor
Expects the whole TradeSkillMaster_Accounting.lua file as a string.
-
#to_csv(output_file) ⇒ Object
initialize.
Constructor Details
#initialize(db_string) ⇒ Database
Expects the whole TradeSkillMaster_Accounting.lua file as a string.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/tsm-accounting.rb', line 40 def initialize(db_string) database = extract_data(db_string) @data = {} database.each do |realm_name,realm_data| @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'],'sale') @data[realm_name][faction_name]['purchase'] = parse_rope(faction_data['buy'],'purchase') end # faction end # realms end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
37 38 39 |
# File 'lib/tsm-accounting.rb', line 37 def data @data end |
Instance Method Details
#to_csv(output_file) ⇒ Object
initialize
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/tsm-accounting.rb', line 54 def to_csv(output_file) CSV.open(output_file, 'w') do |f| f << ['Realm','Faction','Transaction Type','Time','Item ID','Item Name','Quantity','Stack Size','Price (g)','Price (c)','Buyer','Seller'] @data.each do |realm,factions| factions.each do |faction,ropes| ropes.each do |type,items| items.each do |name,item| item.transactions.each do |tx| row = [realm,faction,type] row << tx.datetime.strftime('%Y-%m-%d %k:%M:%S') row << item.id row << item.name row << tx.quantity row << tx.stack_size row << tx.usable_price row << tx.price row << tx.buyer row << tx.seller f << row end end end end end end # close CSV end |