class LedgerLite::V2::Ledger

ledger for commodities (e.g.tulips) / assets / etc.

Public Instance Methods

send( from, to, qty, name ) click to toggle source

apply/do single transaction - send commodity/assets - do transfer

- find a different name - why? why not?
# File lib/ledger-lite/base.rb, line 229
def send( from, to, qty, name )

  if sufficient?( from, qty, name )
    if self.class.config.coinbase?( from )
      # note: coinbase has unlimited funds!! ("virtual" built-in money printing address)
    else
       @addr[ from ][ name ] -= qty
    end
    @addr[ to ] ||= {}     ## make sure addr exists (e.g. init with empty hash {})
    @addr[ to ][ name ] ||= 0
    @addr[ to ][ name ] += qty
  end
end
Also aliased as: transfer
sufficient?( addr, qty, name ) click to toggle source

find a better name - why? why not?

# File lib/ledger-lite/base.rb, line 218
def sufficient?( addr, qty, name )
  return true   if self.class.config.coinbase?( addr )    ## note: coinbase has unlimited funds!!!

  @addr.has_key?( addr ) &&
  @addr[addr].has_key?( name ) &&
  @addr[addr][name] - qty >= 0
end
transfer( from, to, qty, name )

note: transfer is an alias for send (payment)

Alias for: send
unpack( tx ) click to toggle source
# File lib/ledger-lite/base.rb, line 195
def unpack( tx )
  ## "unpack" from, to, amount values

  puts "unpack:"
  pp tx

  if tx.is_a?( Hash )   ## support hashes
    from   = tx[:from]
    to     = tx[:to]
    qty    = tx[:qty]    ## check: use different name e.g. amount, num, etc. why? why not?
    name   = tx[:name]   ## check: use different name e.g. title, what, etc. why? why not?
  else   ## assume it's a transaction (tx) struct/class
    from   = tx.from
    to     = tx.to
    qty    = tx.qty
    name   = tx.name
  end
  [from,to,qty,name]
end