class Flor::Pro::Rand

Public Instance Methods

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

  @node['atts'] = []
end
receive_last() click to toggle source
# File lib/flor/pcore/rand.rb, line 30
def receive_last

  a, b = determine_bounds

  fail Flor::FlorError.new(
    "'#{tree[0]}' expects an integer or a float", self
  ) unless is_number?(a) && is_number?(b)

  payload['ret'] = Random.rand(a...b)

  wrap
end

Protected Instance Methods

determine_bounds() click to toggle source
# File lib/flor/pcore/rand.rb, line 50
def determine_bounds

  nums = @node['atts']
    .inject([]) { |a, (k, v)| a << v if k.nil? && is_number?(v); a }

  return nums[0, 2] if nums.size > 1
  return [ 0, nums.first ] if nums.size == 1
  [ 0, payload['ret'] ]
end
is_number?(o) click to toggle source
# File lib/flor/pcore/rand.rb, line 45
def is_number?(o)

  o.is_a?(Integer) || o.is_a?(Float)
end