Class: TSMAccounting::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/tsm-accounting.rb

Overview

item

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(encoded_string, type) ⇒ Transaction

Returns a new instance of Transaction.



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/tsm-accounting.rb', line 234

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

  @stack_size = TSMAccounting.decode(d[0])
  @quantity = TSMAccounting.decode(d[1])
  @datetime = Time.at(TSMAccounting.decode(d[2]))
  @price = TSMAccounting.decode(d[3])

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

Instance Attribute Details

#buyerObject (readonly)

Returns the value of attribute buyer.



232
233
234
# File 'lib/tsm-accounting.rb', line 232

def buyer
  @buyer
end

#datetimeObject (readonly)

Returns the value of attribute datetime.



232
233
234
# File 'lib/tsm-accounting.rb', line 232

def datetime
  @datetime
end

#priceObject (readonly)

Returns the value of attribute price.



232
233
234
# File 'lib/tsm-accounting.rb', line 232

def price
  @price
end

#quantityObject (readonly)

Returns the value of attribute quantity.



232
233
234
# File 'lib/tsm-accounting.rb', line 232

def quantity
  @quantity
end

#sellerObject (readonly)

Returns the value of attribute seller.



232
233
234
# File 'lib/tsm-accounting.rb', line 232

def seller
  @seller
end

#stack_sizeObject (readonly)

Returns the value of attribute stack_size.



232
233
234
# File 'lib/tsm-accounting.rb', line 232

def stack_size
  @stack_size
end

Instance Method Details

#usable_priceObject

initialize



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/tsm-accounting.rb', line 251

def usable_price
  price = @price.to_s.rjust(5,'0')
  parts = {
    'gold' => price[0..-5].to_i,
    'silver' => price[-4..2].to_i,
    'copper' => price[-2..2].to_i
  }

  # Round up the copper.
  parts['silver'] += 1 if parts['copper'] > 50

  # If this was a <50c transaction, set silver to 1 so
  # it doesn't confuse people.
  if parts['gold'] == 0 and parts['silver'] == 0 and parts['copper'] < 50
    parts['silver'] = 1
  end
  
  return "#{parts['gold']}.#{parts['silver']}".to_f
end