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) ⇒ RDF::Writable

Inserts RDF data into ‘self`.

Parameters:

Returns:



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) ⇒ RDF::Writable Also known as: insert!

Inserts RDF statements into ‘self`.

Parameters:

Returns:



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rdf/mixin/writable.rb', line 51

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

  return self
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?
  true
end