Class: ROBundle::Aggregate

Inherits:
ManifestEntry show all
Defined in:
lib/ro-bundle/ro/aggregate.rb

Overview

A class to represent an aggregated resource in a Research Object. It holds standard meta-data for either file or URI resources. An aggregate can only represent a file path OR a URI resource, not both at once.

If a file path is passed, it will be correctly encoded into a valid absolute URI. If an absolute URI is passed, it is assumed to already have been encoded.

Instance Method Summary collapse

Methods included from Provenance

#add_author, #authored_by, #authored_on, #authored_on=, #created_by, #created_by=, #created_on, #created_on=, #remove_author, #retrieved_by, #retrieved_by=, #retrieved_from, #retrieved_from=, #retrieved_on, #retrieved_on=

Constructor Details

#initialize(object, mediatype = nil) ⇒ Aggregate

:call-seq:

new(uri, mediatype)
new(uri)
new(filepath)
new(filepath, mediatype)

Create a new file or URI aggregate.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ro-bundle/ro/aggregate.rb', line 27

def initialize(object, mediatype = nil)
  super()

  if object.instance_of?(Hash)
    init_json(object)
  else
    @structure[:uri] = if Util.is_absolute_uri?(object)
                         object.to_s
                       else
                         Addressable::URI.encode(object.start_with?("/") ? object : "/#{object}")
                       end
    @structure[:mediatype] = mediatype
  end
end

Instance Method Details

#edited?Boolean

:call-seq:

edited? -> true or false

Has this aggregate been altered in any way?

Returns:

  • (Boolean)


46
47
48
# File 'lib/ro-bundle/ro/aggregate.rb', line 46

def edited?
  @edited || (proxy.nil? ? false : proxy.edited?)
end

#file_entryObject

:call-seq:

file_entry

The path of this aggregate in “rubyzip” format, i.e. no leading ‘/’.



54
55
56
# File 'lib/ro-bundle/ro/aggregate.rb', line 54

def file_entry
  Addressable::URI.unencode(Util.strip_leading_slash(uri)) unless Util.is_absolute_uri?(uri)
end

#mediatypeObject

:call-seq:

mediatype

This aggregate’s IANA media type.



71
72
73
# File 'lib/ro-bundle/ro/aggregate.rb', line 71

def mediatype
  @structure[:mediatype]
end

#proxyObject

:call-seq:

proxy -> Proxy

Return this aggregate’s ORE proxy as per the specification of the JSON structure of the manifest.



81
82
83
# File 'lib/ro-bundle/ro/aggregate.rb', line 81

def proxy
  @structure[:bundledAs]
end

#storedObject

:stopdoc: For internal use only!



96
97
98
99
# File 'lib/ro-bundle/ro/aggregate.rb', line 96

def stored
  super
  proxy.stored unless proxy.nil?
end

#to_json(*a) ⇒ Object

:call-seq:

to_json(options = nil) -> String

Write this Aggregate out as a json string. Takes the same options as JSON#generate.



90
91
92
# File 'lib/ro-bundle/ro/aggregate.rb', line 90

def to_json(*a)
  JSON.generate(Util.clean_json(@structure),*a)
end

#uriObject

:call-seq:

uri

The URI of this aggregate. It should be an absolute URI.



62
63
64
# File 'lib/ro-bundle/ro/aggregate.rb', line 62

def uri
  @structure[:uri]
end