Class: Ezid::Identifier
- Inherits:
-
Object
- Object
- Ezid::Identifier
- Extended by:
- Forwardable
- Defined in:
- lib/ezid/identifier.rb
Overview
Represents an EZID identifier as a resource.
Constant Summary collapse
- INSPECT_ATTRS =
Attributes to display on inspect
%w( id status target created )- PUBLIC =
EZID status terms
"public"- RESERVED =
"reserved"- UNAVAILABLE =
"unavailable"
Class Attribute Summary collapse
Instance Attribute Summary collapse
- #client ⇒ Object readonly
- #id ⇒ Object readonly
- #metadata ⇒ Object
- #shoulder ⇒ Object
Class Method Summary collapse
-
.create(attrs = {}) ⇒ Ezid::Identifier
Creates or mints an identifier (depending on arguments).
-
.find(id) ⇒ Ezid::Identifier
Retrieves an identifier.
Instance Method Summary collapse
-
#delete ⇒ Ezid::Identifier
Deletes the identifier from EZID.
-
#deleted? ⇒ Boolean
Has the identifier been deleted?.
-
#initialize(args = {}) ⇒ Identifier
constructor
A new instance of Identifier.
- #inspect ⇒ Object
-
#persisted? ⇒ Boolean
Is the identifier persisted?.
-
#public? ⇒ Boolean
Is the identifier public?.
-
#reload ⇒ Ezid::Identifier
Reloads the metadata from EZID (local changes will be lost!).
-
#reserved? ⇒ Boolean
Is the identifier reserved?.
-
#reset ⇒ Ezid::Identifier
Empties the (local) metadata (changes will be lost!).
-
#save ⇒ Ezid::Identifier
Persist the identifer and/or metadata to EZID.
- #to_s ⇒ Object
-
#unavailable? ⇒ Boolean
Is the identifier unavailable?.
-
#update(data = {}) ⇒ Ezid::Identifier
Updates the metadata and saves the identifier.
-
#update_metadata(attrs = {}) ⇒ Ezid::Identifier
Updates the metadata.
Constructor Details
#initialize(args = {}) ⇒ Identifier
Returns a new instance of Identifier.
49 50 51 52 53 54 55 |
# File 'lib/ezid/identifier.rb', line 49 def initialize(args={}) @client = args.delete(:client) || Client.new @id = args.delete(:id) @shoulder = args.delete(:shoulder) @deleted = false (args) end |
Class Attribute Details
.defaults ⇒ Object
27 28 29 |
# File 'lib/ezid/identifier.rb', line 27 def defaults @defaults end |
Instance Attribute Details
#client ⇒ Object (readonly)
12 13 14 |
# File 'lib/ezid/identifier.rb', line 12 def client @client end |
#id ⇒ Object (readonly)
12 13 14 |
# File 'lib/ezid/identifier.rb', line 12 def id @id end |
#metadata ⇒ Object
13 14 15 |
# File 'lib/ezid/identifier.rb', line 13 def end |
#shoulder ⇒ Object
13 14 15 |
# File 'lib/ezid/identifier.rb', line 13 def shoulder @shoulder end |
Class Method Details
.create(attrs = {}) ⇒ Ezid::Identifier
Creates or mints an identifier (depending on arguments)
33 34 35 36 |
# File 'lib/ezid/identifier.rb', line 33 def create(attrs = {}) identifier = new(attrs) identifier.save end |
.find(id) ⇒ Ezid::Identifier
Retrieves an identifier
41 42 43 44 |
# File 'lib/ezid/identifier.rb', line 41 def find(id) identifier = new(id: id) identifier.reload end |
Instance Method Details
#delete ⇒ Ezid::Identifier
Deletes the identifier from EZID
131 132 133 134 135 136 |
# File 'lib/ezid/identifier.rb', line 131 def delete raise Error, "Status must be \"reserved\" to delete (status: \"#{status}\")." unless reserved? client.delete_identifier(id) @deleted = true reset end |
#deleted? ⇒ Boolean
Has the identifier been deleted?
100 101 102 |
# File 'lib/ezid/identifier.rb', line 100 def deleted? @deleted end |
#inspect ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/ezid/identifier.rb', line 57 def inspect attrs = if deleted? "id=\"#{id}\" DELETED" else INSPECT_ATTRS.map { |attr| "#{attr}=\"#{send(attr)}\"" }.join(" ") end "#<#{self.class.name} #{attrs}>" end |
#persisted? ⇒ Boolean
Is the identifier persisted?
93 94 95 96 |
# File 'lib/ezid/identifier.rb', line 93 def persisted? return false if deleted? !!(id && created) end |
#public? ⇒ Boolean
Is the identifier public?
146 147 148 |
# File 'lib/ezid/identifier.rb', line 146 def public? status == PUBLIC end |
#reload ⇒ Ezid::Identifier
Reloads the metadata from EZID (local changes will be lost!)
116 117 118 119 |
# File 'lib/ezid/identifier.rb', line 116 def reload self end |
#reserved? ⇒ Boolean
Is the identifier reserved?
140 141 142 |
# File 'lib/ezid/identifier.rb', line 140 def reserved? status == RESERVED end |
#reset ⇒ Ezid::Identifier
Empties the (local) metadata (changes will be lost!)
123 124 125 126 |
# File 'lib/ezid/identifier.rb', line 123 def reset self end |
#save ⇒ Ezid::Identifier
Persist the identifer and/or metadata to EZID.
If the identifier is already persisted, this is an update operation;
Otherwise, create (if it has an id) or mint (if it has a shoulder)
the identifier.
77 78 79 80 81 |
# File 'lib/ezid/identifier.rb', line 77 def save raise Error, "Cannot save a deleted identifier." if deleted? persisted? ? modify : create_or_mint reload end |
#to_s ⇒ Object
66 67 68 |
# File 'lib/ezid/identifier.rb', line 66 def to_s id end |
#unavailable? ⇒ Boolean
Is the identifier unavailable?
152 153 154 |
# File 'lib/ezid/identifier.rb', line 152 def unavailable? status == UNAVAILABLE end |
#update(data = {}) ⇒ Ezid::Identifier
Updates the metadata and saves the identifier
108 109 110 111 |
# File 'lib/ezid/identifier.rb', line 108 def update(data={}) (data) save end |
#update_metadata(attrs = {}) ⇒ Ezid::Identifier
Updates the metadata
86 87 88 89 |
# File 'lib/ezid/identifier.rb', line 86 def (attrs={}) attrs.each { |k, v| send("#{k}=", v) } self end |