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
Create a new file or URI aggregate.
# 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
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
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
This aggregate's IANA media type.
# File lib/ro-bundle/ro/aggregate.rb 71 def mediatype 72 @structure[:mediatype] 73 end
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
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
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
# 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