From dcf205fc932ab96cc011e9bba1274b56a2c27fa3 Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 28 Jun 2014 13:07:39 +0100 Subject: [PATCH] Read createdBy and authoredBy from the manifest. Return the Agent and list of Agents, respectively. --- lib/ro-bundle/file.rb | 18 ++++++++++++++++++ test/tc_read.rb | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/lib/ro-bundle/file.rb b/lib/ro-bundle/file.rb index 66e586a..1e54434 100644 --- a/lib/ro-bundle/file.rb +++ b/lib/ro-bundle/file.rb @@ -64,6 +64,14 @@ def created_on parse_time(:createdOn) end + # :call-seq: + # created_by -> Agent + # + # Return the Agent that created this Research Object. + def created_by + @created_by ||= Agent.new(manifest["createdBy"]) + end + # :call-seq: # authored_on -> Time # @@ -72,6 +80,16 @@ def authored_on parse_time(:authoredOn) end + # :call-seq: + # authored_by -> Agents + # + # Return the list of Agents that authored this Research Object. + def authored_by + @authored_by ||= (manifest["authoredBy"] || []).map do |agent| + Agent.new(agent) + end + end + protected def manifest diff --git a/test/tc_read.rb b/test/tc_read.rb index d22a7df..7b21b8a 100644 --- a/test/tc_read.rb +++ b/test/tc_read.rb @@ -22,8 +22,15 @@ def test_verify def test_manifest ROBundle::File.open($hello) do |b| assert_equal("/", b.id) + assert b.created_on.instance_of?(Time) assert_nil b.authored_on + + creator = b.created_by + assert creator.instance_of?(ROBundle::Agent) + + author = b.authored_by + assert author.instance_of?(Array) end end