OK.

Is this ok for you?

# transfer the given fraction of aliquot from tube-like asset(s)
      # to tube-like asset(s)
      def _call_in_session(session)
        sources = []
        targets = []
        transfers.each do |transfer|
          fraction = transfer["fraction"]
          next unless fraction
          amount = transfer["source"].quantity * fraction
          transfer["amount"] = amount
        end

        transfers.each do |transfer|
          source = transfer["source"]
          target = transfer["target"]
          target << source.take_amount(transfer["amount"])

          unless transfer["aliquot_type"].nil?
            target.each do |aliquot|
              aliquot.type = transfer["aliquot_type"]
            end
          end

          sources << source
          targets << target
        end

        { :sources => sources.uniq, :targets => targets.uniq}
      end

Thanks,

Karoly

On 11 Feb 2013, at 11:51, maxigit wrote:

> In lib/lims-core/actions/transfer_tubes_to_tubes.rb:
> 
> > @@ -38,6 +38,8 @@ def validAmountAndFraction
> >        # transfer the given fraction of aliquot from tube-like asset(s)
> >        # to tube-like asset(s)
> >        def _call_in_session(session)
> > +        sources = []
> > +        targets = []
> >          transfers.each do |transfer|
> >            next unless transfer["fraction"]
> >            amount = transfer["source"].quantity * transfer["fraction"]
> I would prefer source = transfer["source"] and then using source.
> One can think it's premature optimization but the main goal is to be DRY and avoid error.
> If there is a spelling mistake, let's say
> 
> transfer["faction"]
> It's really hard to spot especially because the other similar lines are OK.
> Also if we change the JSON, you only need to modify the key once ...
> 
> —
> Reply to this email directly or view it on GitHub..
> 
>