Class: ROBundle::Agent
- Inherits:
-
Object
- Object
- ROBundle::Agent
- Defined in:
- lib/ro-bundle/ro/agent.rb
Overview
A class to represent an agent in a Research Object. An agent can be, for example, a person or software.
Instance Method Summary collapse
-
#initialize(first, uri = nil, orcid = nil) ⇒ Agent
constructor
:call-seq: new(name, uri = nil, orcid = nil).
-
#name ⇒ Object
:call-seq: name -> string.
-
#orcid ⇒ Object
:call-seq: orcid -> URI.
-
#to_json(*a) ⇒ Object
:call-seq: to_json(options = nil) -> String.
-
#uri ⇒ Object
:call-seq: uri -> URI.
Constructor Details
#initialize(first, uri = nil, orcid = nil) ⇒ Agent
:call-seq:
new(name, uri = nil, orcid = nil)
Create a new Agent with the supplied details. If uri or orcid are not absolute URIs then they are set to nil.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ro-bundle/ro/agent.rb', line 21 def initialize(first, uri = nil, orcid = nil) if first.instance_of?(Hash) name = first[:name] uri = first[:uri] orcid = first[:orcid] else name = first end @structure = { :name => name, :uri => Util.is_absolute_uri?(uri) ? uri.to_s : nil, :orcid => Util.is_absolute_uri?(orcid) ? orcid.to_s : nil } end |
Instance Method Details
#name ⇒ Object
:call-seq:
name -> string
The name of this agent.
41 42 43 |
# File 'lib/ro-bundle/ro/agent.rb', line 41 def name @structure[:name] end |
#orcid ⇒ Object
:call-seq:
orcid -> URI
An ORCID identifier URI for this agent.
58 59 60 |
# File 'lib/ro-bundle/ro/agent.rb', line 58 def orcid @structure[:orcid] end |
#to_json(*a) ⇒ Object
:call-seq:
to_json(options = nil) -> String
Write this Agent out as a json string. Takes the same options as JSON#generate.
67 68 69 |
# File 'lib/ro-bundle/ro/agent.rb', line 67 def to_json(*a) JSON.generate(Util.clean_json(@structure),*a) end |
#uri ⇒ Object
50 51 52 |
# File 'lib/ro-bundle/ro/agent.rb', line 50 def uri @structure[:uri] end |