Module: RDF::Writable

Extended by:
Util::Aliasing::LateBound
Included in:
Mutable, Writer
Defined in:
lib/rdf/mixin/writable.rb

Overview

Classes that include this module must implement the methods #insert_statement.

See Also:

Instance Method Summary collapse

Methods included from Util::Aliasing::LateBound

alias_method

Instance Method Details

#<<(data) ⇒ self

Inserts RDF data into self.

Parameters:

Returns:

  • (self)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rdf/mixin/writable.rb', line 25

def <<(data)
  case data
    when RDF::Reader
      insert_reader(data)
    when RDF::Graph
      insert_graph(data)
    when RDF::Enumerable
      insert_statements(data)
    when RDF::Statement
      insert_statement(data)
    else case
      when data.respond_to?(:to_rdf) && !data.equal?(rdf = data.to_rdf)
        self << rdf
      else
        insert_statement(Statement.from(data))
    end
  end

  return self
end

#insert(*statements) ⇒ self #insert(statements) ⇒ self Also known as: insert!

Note:

using splat argument syntax with excessive arguments provided

Inserts RDF statements into self.

significantly affects performance. Use Enumerator form for large numbers of statements.

Overloads:

  • #insert(*statements) ⇒ self

    Parameters:

    Returns:

    • (self)
  • #insert(statements) ⇒ self

    Parameters:

    Returns:

    • (self)


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rdf/mixin/writable.rb', line 60

def insert(*statements)
  statements.map! do |value|
    case
      when value.respond_to?(:each_statement)
        insert_statements(value)
        nil
      when (statement = Statement.from(value))
        statement
      else
        raise ArgumentError.new("not a valid statement: #{value.inspect}")
    end
  end
  statements.compact!
  insert_statements(statements) unless statements.empty?

  return self
end

#insert_graph(graph) (protected)

This method returns an undefined value.

Inserts the given RDF graph into the underlying storage or output stream.

Defaults to passing the graph to the #insert_statements method.

Subclasses of Repository may wish to override this method in case their underlying storage architecture is graph-centric rather than statement-oriented.

Subclasses of RDF::Writer may wish to override this method if the output format they implement supports named graphs, in which case implementing this method may help in producing prettier and more concise output.

Parameters:



116
117
118
# File 'lib/rdf/mixin/writable.rb', line 116

def insert_graph(graph)
  insert_statements(graph)
end

#insert_reader(reader) (protected)

This method returns an undefined value.

Inserts statements from the given RDF reader into the underlying storage or output stream.

Defaults to passing the reader to the #insert_statements method.

Subclasses of Repository may wish to override this method in case their underlying storage can efficiently import RDF data directly in particular serialization formats, thus avoiding the intermediate parsing overhead.

Parameters:

Since:

  • 0.2.3



95
96
97
# File 'lib/rdf/mixin/writable.rb', line 95

def insert_reader(reader)
  insert_statements(reader)
end

#insert_statement(statement) (protected)

This method is abstract.

This method returns an undefined value.

Inserts an RDF statement into the underlying storage or output stream.

Subclasses of Repository must implement this method, except if they are immutable.

Subclasses of RDF::Writer must implement this method.

Parameters:

Raises:

  • (NotImplementedError)


154
155
156
# File 'lib/rdf/mixin/writable.rb', line 154

def insert_statement(statement)
  raise NotImplementedError.new("#{self.class}#insert_statement")
end

#insert_statements(statements) (protected)

This method returns an undefined value.

Inserts the given RDF statements into the underlying storage or output stream.

Defaults to invoking #insert_statement for each given statement.

Subclasses of Repository may wish to override this method if they are capable of more efficiently inserting multiple statements at once.

Subclasses of RDF::Writer don't generally need to implement this method.

Parameters:

Since:

  • 0.1.6



136
137
138
139
140
141
# File 'lib/rdf/mixin/writable.rb', line 136

def insert_statements(statements)
  each = statements.respond_to?(:each_statement) ? :each_statement : :each
  statements.__send__(each) do |statement|
    insert_statement(statement)
  end
end

#writable?Boolean

Returns true if self is writable.

Returns:

  • (Boolean)

    true or false

See Also:



16
17
18
# File 'lib/rdf/mixin/writable.rb', line 16

def writable?
  !frozen?
end