Class: PushmiPullyu::AIP::OwnerEmailEditor

Inherits:
Object
  • Object
show all
Defined in:
lib/pushmi_pullyu/aip/owner_email_editor.rb

Defined Under Namespace

Classes: NoOwnerPredicate

Constant Summary collapse

OWNER_PREDICATE =
RDF::URI('http://purl.org/ontology/bibo/owner').freeze

Instance Method Summary collapse

Constructor Details

#initialize(rdf_string) ⇒ OwnerEmailEditor

Returns a new instance of OwnerEmailEditor.


9
10
11
# File 'lib/pushmi_pullyu/aip/owner_email_editor.rb', line 9

def initialize(rdf_string)
  @document = rdf_string
end

Instance Method Details

#runObject

Raises:


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pushmi_pullyu/aip/owner_email_editor.rb', line 13

def run
  setup_db_connection
  is_modified = false
  prefixes = nil
  # Read once to load prefixes (the @things at the top of an n3 file)
  RDF::N3::Reader.new(input = @document) do |reader|
    reader.each_statement { |_statement| }
    prefixes = reader.prefixes
  end
  new_body = RDF::N3::Writer.buffer(prefixes: prefixes) do |writer|
    RDF::N3::Reader.new(input = @document) do |reader|
      reader.each_statement do |statement|
        if statement.predicate == OWNER_PREDICATE
          user = PushmiPullyu::AIP::User.find(statement.object.to_i)
          writer << [statement.subject, statement.predicate, user.email]
          is_modified = true
        else
          writer << statement
        end
      end
    end
  end
  return new_body if is_modified

  raise NoOwnerPredicate
end