demo/my_functions.rb
# Compute amount and return BigDecimal
# Optionally inject symbol for relevant amount column
Compute amount and return BigDecimal
Optionally inject symbol for relevant amount column
Compute amount and return BigDecimal Optionally inject symbol for relevant amount column
def compute_amount( tx, dt, amnt=:amount )
    	amount = BigDecimal.new("0.00")
      if tx[amnt]
      	tmpno = tx[amnt].to_s
      	if tmpno =~ /,[0-9]+$/
      		tmpno = tmpno.gsub(/\./, '').gsub(/,/, '.')
      	else
      		tmpno = tmpno.gsub(/,/, '')
      	end
        amount = BigDecimal.new(tmpno)
        tx[amnt] = amount.to_s("F") 
      else 
        amount = BigDecimal.new("0.01") * BigDecimal.new(dt.day)  
        if tx[:amountspecial]
          amount = amount + BigDecimal.new(tx[:amountspecial])
        end
        if tx[:nr]
	        amount = amount + BigDecimal.new(tx[:nr]) 
	      end
        tx[amnt] = amount.to_s("F") 
      end
      amount 
    end
def compute_amount ( tx , dt , amnt = :amount ) amount = BigDecimal . new ( "0.00" ) if tx [ amnt ] tmpno = tx [ amnt ] . to_s if tmpno =~ / ,[0-9]+$ / tmpno = tmpno . gsub ( / \. / , '' ) . gsub ( / , / , '.' ) else tmpno = tmpno . gsub ( / , / , '' ) end amount = BigDecimal . new ( tmpno ) tx [ amnt ] = amount . to_s ( "F" ) else amount = BigDecimal . new ( "0.01" ) * BigDecimal . new ( dt . day ) if tx [ :amountspecial ] amount = amount + BigDecimal . new ( tx [ :amountspecial ] ) end if tx [ :nr ] amount = amount + BigDecimal . new ( tx [ :nr ] ) end tx [ amnt ] = amount . to_s ( "F" ) end amount end
Compute amount and return BigDecimal
Optionally inject symbol for relevant amount column
Compute amount and return BigDecimal Optionally inject symbol for relevant amount column
# take given value if any # Convert amount to string else it may be interpreted as a Rational # Convert to american format if in german, i.e. swap usage of . and ,  # Format output as string # compute value according to actual day and index # decimal part according to day of date # plus running index # Format output as string # Return BigDecimal for further computing
tx
<not_specific>
dt
<not_specific>
amnt
<not_specific>