class ROBundle::Aggregate

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.

Public Class Methods

new(uri, mediatype) click to toggle source
new(uri)
new(filepath)
new(filepath, mediatype)

Create a new file or URI aggregate.

Calls superclass method
   # File lib/ro-bundle/ro/aggregate.rb
27 def initialize(object, mediatype = nil)
28   super()
29 
30   if object.instance_of?(Hash)
31     init_json(object)
32   else
33     @structure[:uri] = if Util.is_absolute_uri?(object)
34                          object.to_s
35                        else
36                          Addressable::URI.encode(object.start_with?("/") ? object : "/#{object}")
37                        end
38     @structure[:mediatype] = mediatype
39   end
40 end

Public Instance Methods

edited? → true or false click to toggle source

Has this aggregate been altered in any way?

   # File lib/ro-bundle/ro/aggregate.rb
46 def edited?
47   @edited || (proxy.nil? ? false : proxy.edited?)
48 end
file_entry click to toggle source

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

   # File lib/ro-bundle/ro/aggregate.rb
54 def file_entry
55   Addressable::URI.unencode(Util.strip_leading_slash(uri)) unless Util.is_absolute_uri?(uri)
56 end
mediatype click to toggle source

This aggregate's IANA media type.

   # File lib/ro-bundle/ro/aggregate.rb
71 def mediatype
72   @structure[:mediatype]
73 end
proxy → Proxy click to toggle source

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

   # File lib/ro-bundle/ro/aggregate.rb
81 def proxy
82   @structure[:bundledAs]
83 end
to_json(options = nil) → String click to toggle source

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

   # File lib/ro-bundle/ro/aggregate.rb
90 def to_json(*a)
91   JSON.generate(Util.clean_json(@structure),*a)
92 end
uri click to toggle source

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

   # File lib/ro-bundle/ro/aggregate.rb
62 def uri
63   @structure[:uri]
64 end

Private Instance Methods

init_json(object) click to toggle source
    # File lib/ro-bundle/ro/aggregate.rb
104 def init_json(object)
105   @structure = init_provenance_defaults(object)
106   @structure[:uri] = object[:uri]
107   @structure[:mediatype] = object[:mediatype]
108   unless object[:bundledAs].nil?
109     @structure[:bundledAs] = Proxy.new(object[:bundledAs])
110   end
111 end