class Wongi::Engine::JoinResults

Attributes

by_token[R]
by_wme[R]
hidden[R]

Public Class Methods

new() click to toggle source
# File lib/wongi-engine/join_results.rb, line 6
def initialize
  @by_wme = Hash.new { |h, k| h[k] = {} }
  @by_token = Hash.new { |h, k| h[k] = {} }
  @hidden = {}
end

Public Instance Methods

add(jr) click to toggle source
# File lib/wongi-engine/join_results.rb, line 30
def add(jr)
  if hidden.key?(jr)
    hidden.delete(jr)
  else
    by_wme[jr.wme][jr] = true
    by_token[jr.token.object_id][jr] = true
  end
end
for(wme: nil, token: nil) click to toggle source
# File lib/wongi-engine/join_results.rb, line 12
def for(wme: nil, token: nil)
  if wme
    by_wme.key?(wme) ? by_wme[wme].keys : []
  elsif token
    by_token.key?(token.object_id) ? by_token[token.object_id].keys : []
  else
    []
  end
end
has?(jr) click to toggle source
# File lib/wongi-engine/join_results.rb, line 22
def has?(jr)
  by_wme.key?(jr.wme) && by_wme[jr.wme].key?(jr)
end
hidden?(jr) click to toggle source
# File lib/wongi-engine/join_results.rb, line 26
def hidden?(jr)
  hidden.key?(jr)
end
hide(jr) click to toggle source
# File lib/wongi-engine/join_results.rb, line 60
def hide(jr)
  hidden[jr] = true
end
remove(jr) click to toggle source
# File lib/wongi-engine/join_results.rb, line 39
def remove(jr)
  unless has?(jr)
    hide(jr)
    return
  end

  if by_wme.key?(jr.wme)
    by_wme[jr.wme].delete(jr)
    if by_wme[jr.wme].empty?
      by_wme.delete(jr.wme)
    end
  end

  if by_token.key?(jr.token.object_id)
    by_token[jr.token.object_id].delete(jr)
    if by_token[jr.token.object_id].empty?
      by_token.delete(jr.token.object_id)
    end
  end
end
remove_token(token) click to toggle source
# File lib/wongi-engine/join_results.rb, line 64
def remove_token(token)
  return unless by_token.key?(token.object_id)

  by_token[token.object_id].keys.each do |jr|
    remove(jr)
  end
end
remove_wme(wme) click to toggle source
# File lib/wongi-engine/join_results.rb, line 72
def remove_wme(wme)
  return unless by_wme.key?(wme)

  by_wme[wme].keys do |jr|
    remove(jr)
  end
end