class Wongi::Engine::EntityIterator

Attributes

collection[R]
entity[R]

Public Class Methods

new(entity, collection) click to toggle source
# File lib/wongi-engine/entity_iterator.rb, line 7
def initialize(entity, collection)
  @entity = entity
  @collection = collection
end

Public Instance Methods

[](name) click to toggle source
# File lib/wongi-engine/entity_iterator.rb, line 31
def [](name)
  get(name)
end
each() { |predicate, object| ... } click to toggle source
# File lib/wongi-engine/entity_iterator.rb, line 12
def each
  if block_given?
    @collection.each do |wme|
      yield wme.predicate, wme.object
    end
  else
    Enumerator.new do |y|
      @collection.each do |wme|
        y << [wme.predicate, wme.object]
      end
    end
  end
end
fetch(name, *args, &block) click to toggle source
# File lib/wongi-engine/entity_iterator.rb, line 39
def fetch(name, *args, &block)
  each { |k, v| return v if k == name }
  if args.first
    args.first
  elsif block
    block.call(name)
  else
    raise KeyError
  end
end
get(name) click to toggle source
# File lib/wongi-engine/entity_iterator.rb, line 26
def get(name)
  each { |k, v| return v if k == name }
  nil
end
get_all(name) click to toggle source
# File lib/wongi-engine/entity_iterator.rb, line 35
def get_all(name)
  each.filter_map { |k, v| v if k == name }
end
method_missing(name) click to toggle source
# File lib/wongi-engine/entity_iterator.rb, line 50
def method_missing(name)
  each { |k, v| return v if k == name }
  raise NoMethodError
end
respond_to_missing?(name, _include_private) click to toggle source
Calls superclass method
# File lib/wongi-engine/entity_iterator.rb, line 55
def respond_to_missing?(name, _include_private)
  each { |k, v| return true if k == name }
  super
end