Class: TSMAccounting::Transaction
- Inherits:
-
Object
- Object
- TSMAccounting::Transaction
- Defined in:
- lib/tsm-accounting.rb
Overview
item
Instance Attribute Summary collapse
-
#buyer ⇒ Object
readonly
Returns the value of attribute buyer.
-
#datetime ⇒ Object
readonly
Returns the value of attribute datetime.
-
#price ⇒ Object
readonly
Returns the value of attribute price.
-
#quantity ⇒ Object
readonly
Returns the value of attribute quantity.
-
#seller ⇒ Object
readonly
Returns the value of attribute seller.
-
#stack_size ⇒ Object
readonly
Returns the value of attribute stack_size.
Instance Method Summary collapse
-
#initialize(encoded_string, type) ⇒ Transaction
constructor
A new instance of Transaction.
-
#usable_price ⇒ Object
initialize.
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
#buyer ⇒ Object (readonly)
Returns the value of attribute buyer.
232 233 234 |
# File 'lib/tsm-accounting.rb', line 232 def buyer @buyer end |
#datetime ⇒ Object (readonly)
Returns the value of attribute datetime.
232 233 234 |
# File 'lib/tsm-accounting.rb', line 232 def datetime @datetime end |
#price ⇒ Object (readonly)
Returns the value of attribute price.
232 233 234 |
# File 'lib/tsm-accounting.rb', line 232 def price @price end |
#quantity ⇒ Object (readonly)
Returns the value of attribute quantity.
232 233 234 |
# File 'lib/tsm-accounting.rb', line 232 def quantity @quantity end |
#seller ⇒ Object (readonly)
Returns the value of attribute seller.
232 233 234 |
# File 'lib/tsm-accounting.rb', line 232 def seller @seller end |
#stack_size ⇒ Object (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_price ⇒ Object
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 |