module Subledger::Rest

Constants

ACCOUNT
BALANCE

TODO eliminate if condition in BALANCE LAMBDA

BOOK
CATEGORIES
IDENTITY
JOURNAL_ENTRY
LAMBDAS
MODE
NB
ORG
REPORT
TIME
VALUE
VERSION

Public Class Methods

present_collection(entity_name, collection) click to toggle source
# File lib/subledger/rest.rb, line 31
def self.present_collection entity_name, collection
  entities = collection.collect { |entity| entity.serializable_hash }

  { entity_name => entities }
end
present_entity(entity) click to toggle source
# File lib/subledger/rest.rb, line 27
def self.present_entity entity
  { entity.entity_name => entity.serializable_hash }
end
to_args(rest_args, client) click to toggle source
# File lib/subledger/rest.rb, line 3
def self.to_args rest_args, client
  args = { }

  rest_args.each do |key, value|
    key_symbol = key.to_sym

    unless value.nil?
      code = LAMBDAS[key]

      args[key_symbol] = if code.nil? or value.kind_of? Domain
                           value
                         else
                           code.call client, args, key, value
                         end
    end
  end

  args
end
to_balance(rest_args, client) click to toggle source
# File lib/subledger/rest.rb, line 23
def self.to_balance rest_args, client
  to_args( rest_args, client )[:balance]
end

Private Class Methods

credit_value(client, amount) click to toggle source
# File lib/subledger/rest.rb, line 124
def self.credit_value client, amount
  BigDecimal( amount ) == 0 ? client.zero : client.credit( amount )
end
debit_value(client, amount) click to toggle source
# File lib/subledger/rest.rb, line 120
def self.debit_value client, amount
  BigDecimal( amount ) == 0 ? client.zero : client.debit( amount )
end