lib/rdf/model/statement.rb in rdf-0.3.0.pre vs lib/rdf/model/statement.rb in rdf-0.3.0
- old
+ new
@@ -22,16 +22,17 @@
include RDF::Value
##
# @private
# @since 0.2.2
- def self.from(statement)
+ def self.from(statement, options = {})
case statement
+ when Array, Query::Pattern
+ self.new(statement[0], statement[1], statement[2], options.merge(:context => statement[3] || nil))
when Statement then statement
- when Hash then self.new(statement)
- when Array then self.new(*statement)
- else raise ArgumentError.new("expected RDF::Statement, Hash, or Array, but got #{statement.inspect}")
+ when Hash then self.new(options.merge(statement))
+ else raise ArgumentError, "expected RDF::Statement, Hash, or Array, but got #{statement.inspect}"
end
end
# @return [Object]
attr_accessor :id
@@ -43,25 +44,25 @@
attr_accessor :subject
# @return [RDF::URI]
attr_accessor :predicate
- # @return [RDF::Value]
+ # @return [RDF::Term]
attr_accessor :object
##
# @overload initialize(options = {})
# @param [Hash{Symbol => Object}] options
# @option options [RDF::Resource] :subject (nil)
# @option options [RDF::URI] :predicate (nil)
- # @option options [RDF::Value] :object (nil)
+ # @option options [RDF::Term] :object (nil)
# @option options [RDF::Resource] :context (nil)
#
# @overload initialize(subject, predicate, object, options = {})
# @param [RDF::Resource] subject
# @param [RDF::URI] predicate
- # @param [RDF::Value] object
+ # @param [RDF::Term] object
# @param [Hash{Symbol => Object}] options
# @option options [RDF::Resource] :context (nil)
def initialize(subject = nil, predicate = nil, object = nil, options = {})
case subject
when Hash
@@ -74,11 +75,11 @@
@subject = subject
@predicate = predicate
@object = object
end
@id = @options.delete(:id) if @options.has_key?(:id)
- @context = @options.delete(:context) || @options.delete(:graph)
+ @context = @options.delete(:context)
initialize!
end
##
# @private
@@ -87,11 +88,11 @@
@subject = Node.intern(@subject) if @subject.is_a?(Symbol)
@predicate = Node.intern(@predicate) if @predicate.is_a?(Symbol)
@object = case @object
when nil then nil
when Symbol then Node.intern(@object)
- when Value then @object
+ when Term then @object
else Literal.new(@object)
end
end
##
@@ -188,11 +189,11 @@
return true
end
##
# @param [Integer] index
- # @return [RDF::Value]
+ # @return [RDF::Term]
def [](index)
case index
when 0 then self.subject
when 1 then self.predicate
when 2 then self.object
@@ -201,12 +202,12 @@
end
end
##
# @param [Integer] index
- # @param [RDF::Value] value
- # @return [RDF::Value]
+ # @param [RDF::Term] value
+ # @return [RDF::Term]
def []=(index, value)
case index
when 0 then self.subject = value
when 1 then self.predicate = value
when 2 then self.object = value
@@ -214,17 +215,17 @@
else nil
end
end
##
- # @return [Array(RDF::Value)]
+ # @return [Array(RDF::Term)]
def to_quad
[subject, predicate, object, context]
end
##
- # @return [Array(RDF::Value)]
+ # @return [Array(RDF::Term)]
def to_triple
[subject, predicate, object]
end
alias_method :to_a, :to_triple
@@ -234,10 +235,10 @@
# Returns the terms of this statement as a `Hash`.
#
# @param [Symbol] subject_key
# @param [Symbol] predicate_key
# @param [Symbol] object_key
- # @return [Hash{Symbol => RDF::Value}]
+ # @return [Hash{Symbol => RDF::Term}]
def to_hash(subject_key = :subject, predicate_key = :predicate, object_key = :object, context_key = :context)
{subject_key => subject, predicate_key => predicate, object_key => object, context_key => context}
end
##