Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added Enumberable#valid?, #invalid? and #validate!

  • Loading branch information...
commit 96c4f36abf5a58294638102447ef73154b7f6210 1 parent d6888bb
@gkellogg gkellogg authored
Showing with 31 additions and 2 deletions.
  1. +31 −2 lib/rdf/mixin/enumerable.rb
View
33 lib/rdf/mixin/enumerable.rb
@@ -76,6 +76,37 @@ def supports?(feature)
end
##
+ # Returns `true` if all statements are valid
+ #
+ # @return [Boolean] `true` or `false`
+ # @since 0.3.11
+ def valid?
+ each_statement do |s|
+ return false if s.invalid?
+ end
+ true
+ end
+
+ ##
+ # Returns `true` if value is not valid
+ #
+ # @return [Boolean] `true` or `false`
+ # @since 0.2.1
+ def invalid?
+ !valid?
+ end
+
+ ##
+ # Default validate! implementation, overridden in concrete classes
+ # @return [RDF::Literal] `self`
+ # @raise [ArgumentError] if the value is invalid
+ # @since 0.3.9
+ def validate!
+ raise ArgumentError if invalid?
+ end
+ alias_method :validate, :validate!
+
+ ##
# Returns all RDF statements.
#
# @param [Hash{Symbol => Boolean}] options
@@ -603,8 +634,6 @@ def to_set
def to_hash
result = {}
each_statement do |statement|
- next if statement.invalid? # skip any incomplete statements
-
result[statement.subject] ||= {}
values = (result[statement.subject][statement.predicate] ||= [])
values << statement.object unless values.include?(statement.object)
Please sign in to comment.
Something went wrong with that request. Please try again.