class Factoid::Factoid

Attributes

context[R]
type[R]
value_obj[R]

Public Class Methods

from_xml(elem, context_sources) click to toggle source
# File lib/factoid/xml.rb, line 50
def Factoid.from_xml(elem, context_sources)
        type = elem.name unless elem.name == 'factoid'
        type ||= elem.attr('type')

        context = {}
        elem.xpath('./*[name(.) != "value"]').each do |e|
                context[e.name] = e.text
        end

        value = Value.from_xml(elem)

        raw_sources = elem.xpath('f:source', NS)
        sources = raw_sources.map do |e|
                Source.from_xml(e)
        end

        return Factoid.new(type, context, value, sources, context_sources)
end
new(type, context, value_obj, sources, context_sources) click to toggle source
# File lib/factoid/factoid.rb, line 6
def initialize(type, context, value_obj, sources, context_sources)
        @type = type
        @context = context
        @value_obj = value_obj

        @sources = sources
        @context_sources = context_sources
end

Public Instance Methods

eql?(other) click to toggle source
# File lib/factoid/factoid.rb, line 41
def eql?(other)
        if other.equal?(self)
                return true
        end

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

        same = other.type == self.type &&
               other.value.eql?(self.value) &&
               other.sources == self.sources

        return same
end
match?(type, context) click to toggle source
# File lib/factoid/factoid.rb, line 29
def match?(type, context)
        if @type != type # FIXME: check type hierarchy
                return false
        end

        return context.to_a.all? { |k, v| @context[k.to_s] == v }
end
sources() click to toggle source
# File lib/factoid/factoid.rb, line 19
def sources
        if !@sources.empty?
                return @sources
        end

        uris = @context_sources.select { |s| s.default? }

        return uris
end
value(interpret = true, follow = false) click to toggle source
# File lib/factoid/factoid.rb, line 37
def value(interpret = true, follow = false)
        return @value_obj.value(interpret, follow)
end