class Flor::Pro::Case

Public Instance Methods

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

  unatt_unkeyed_children

  @node['val'] = payload['ret'] if non_att_count.even?
end
receive() click to toggle source
# File lib/flor/pcore/case.rb, line 143
def receive

  return wrap_reply if @node['found']

  determine_fcid_and_ncid

  return execute_child(@ncid) if @fcid == nil

  has_no_val = ! @node.has_key?('val')

  if has_no_val && ! from_att?
    @node['val'] = payload['ret']
    execute_conditional
  elsif has_no_val
    execute_child(@ncid)
  elsif m = match?
    execute_then(@ncid, m)
  else
    execute_conditional(@ncid + 1)
  end
end

Protected Instance Methods

array() click to toggle source
# File lib/flor/pcore/case.rb, line 215
def array

  a = payload['ret']
  a = [ a ] if Flor.is_regex_tree?(a) || ! a.is_a?(Array)
  a.collect { |e| Flor.is_regex_tree?(e) ? Flor.to_regex(e) : e }
end
do_match?(elt, val) click to toggle source
# File lib/flor/pcore/case.rb, line 205
def do_match?(elt, val)

  return { 'matched' => elt } if elt == val

  m = val.is_a?(String) && elt.is_a?(Regexp) && elt.match(val)
  return { 'matched' => elt, 'match' => m.to_a } if m

  nil
end
else?(ncid) click to toggle source
# File lib/flor/pcore/case.rb, line 187
def else?(ncid)

  (t = tree[1][ncid]) &&
  t[0, 2] == [ 'else', [] ]
end
execute_conditional(ncid=@ncid) click to toggle source
# File lib/flor/pcore/case.rb, line 167
def execute_conditional(ncid=@ncid)

  if else?(ncid)
    execute_then(ncid + 1)
  else
    payload['ret'] = node_payload_ret
    execute_child(ncid)
  end
end
execute_then(ncid, vars=nil) click to toggle source
# File lib/flor/pcore/case.rb, line 177
def execute_then(ncid, vars=nil)

  payload['ret'] = node_payload_ret
  @node['found'] = true

  h = vars.is_a?(Hash) ? { 'vars' => vars } : nil

  execute_child(ncid, nil, h)
end
match?() click to toggle source
# File lib/flor/pcore/case.rb, line 193
def match?

  v = @node['val']

  array.each do |e|
    m = do_match?(e, v)
    return m if m
  end

  nil
end