class Flor::Pro::Range

Public Instance Methods

pre_execute() click to toggle source
# File lib/flor/pcore/range.rb, line 29
def pre_execute

  @node['rets'] = []
  @node['atts'] = []

  unatt_unkeyed_children
end
receive_last() click to toggle source
Calls superclass method Flor::Procedure#receive_last
# File lib/flor/pcore/range.rb, line 37
def receive_last

  rets = @node['rets'].select { |r| r.is_a?(Numeric) }.collect(&:to_i)

  sta = rets[1] ? rets[0] : 0
  edn = rets[1] || rets[0] || 0
  ste = rets[2] || ((sta > edn) ? -1 : 1)

  asta = att('start', 'from')
  aedn = att('end', 'to')
  aste = att('step', 'by', 'inc')

  sta = asta if asta
  edn = aedn if aedn
  ste = aste if aste

  fail Flor::FlorError.new("#{heap} step is 0", self) \
    if ste == 0

  #payload['ret'] = (sta..edn - 1).step(ste).to_a
    # doesn't accept negative steps

  payload['ret'] = []
  cur = sta
    #
  loop do
    break if (ste < 0) ? (cur <= edn) : (cur >= edn)
    payload['ret'] << cur
    cur = cur + ste
  end

  super
end