class Factoid::Entitoid

Attributes

uuid[R]

Public Class Methods

from_xml(filename) click to toggle source
# File lib/factoid/xml.rb, line 21
def Entitoid.from_xml(filename)
        x = Nokogiri::XML(open(filename))

        uuid = x.root.attr('xml:id')
        e = self.new(uuid)

        context_sources = []
        x.xpath('/*/f:sources/f:source').each do |s|
                context_sources << Source.from_xml(s)
        end

        x.xpath('/*/f:*', NS).each do |f|
                if f.name == 'sources'
                        next
                end

                e.add_factoid(Factoid.from_xml(f, context_sources))
        end

        return e
end
new(uuid) click to toggle source
# File lib/factoid/entitoid.rb, line 6
def initialize(uuid)
        @uuid = uuid
        @factoids = []
end

Public Instance Methods

add_factoid(factoid) click to toggle source
# File lib/factoid/entitoid.rb, line 13
def add_factoid(factoid)
        @factoids << factoid
end
eql?(other) click to toggle source
# File lib/factoid/entitoid.rb, line 40
def eql?(other)
        if other.equal?(self)
                return true
        end

        if other.class != self.class
                return false
        end

        f = factoids(:all)
        other_f = other.factoids(:all)

        return f.eql?(other_f)
end
factoids(name, context = {}) click to toggle source
# File lib/factoid/entitoid.rb, line 17
def factoids(name, context = {})
        if name == :all
                return @factoids
        end

        matching = @factoids.select { |f| f.match?(name, context) }
        return matching
end
value(name, context = {}) click to toggle source
# File lib/factoid/entitoid.rb, line 26
def value(name, context = {})
        f = factoids(name, context)

        if f.empty?
                raise "Cannot return value, no factoid matches name: '#{name}', context: #{context}"
        end

        if f.count > 1
                raise "Cannot return value, too many factoids match name: '#{name}', context: #{context}"
        end

        return f.first.value
end