Class: ROBundle::Aggregate
- Inherits:
-
ManifestEntry
- Object
- ManifestEntry
- ROBundle::Aggregate
- 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
-
#edited? ⇒ Boolean
:call-seq: edited? -> true or false.
-
#file_entry ⇒ Object
:call-seq: file_entry.
-
#initialize(object, mediatype = nil) ⇒ Aggregate
constructor
:call-seq: new(uri, mediatype) new(uri) new(filepath) new(filepath, mediatype).
-
#mediatype ⇒ Object
:call-seq: mediatype.
-
#proxy ⇒ Object
:call-seq: proxy -> Proxy.
-
#stored ⇒ Object
:stopdoc: For internal use only!.
-
#to_json(*a) ⇒ Object
:call-seq: to_json(options = nil) -> String.
-
#uri ⇒ Object
:call-seq: uri.
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?
46 47 48 |
# File 'lib/ro-bundle/ro/aggregate.rb', line 46 def edited? @edited || (proxy.nil? ? false : proxy.edited?) end |
#file_entry ⇒ Object
: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 |
#mediatype ⇒ Object
71 72 73 |
# File 'lib/ro-bundle/ro/aggregate.rb', line 71 def mediatype @structure[:mediatype] end |
#proxy ⇒ Object
: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 |
#stored ⇒ Object
: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 |
#uri ⇒ Object
: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 |