Class: Aspire::Object::User

Inherits:
Base
  • Object
show all
Defined in:
lib/aspire/object/user.rb

Overview

Represents a user profile in the Aspire API

Constant Summary

Constants inherited from Base

Base::STRIP_HTML

Constants included from Util

Util::LD_API_URI

Instance Attribute Summary collapse

Attributes inherited from Base

#factory, #uri

Instance Method Summary collapse

Methods inherited from Base

#get_boolean, #get_date, #get_property

Methods included from Util

#child_url?, #duration, #id_from_uri, #item?, #linked_data, #linked_data_path, #list?, #list_url?, #module?, #parent_url?, #parse_url, #resource?, #section?, #url_for_comparison, #url_path, #user?

Constructor Details

#initialize(uri, factory, json: nil, ld: nil) ⇒ void

Initialises a new User instance

Parameters:

  • uri (String)

    the URI of the user profile

  • factory (Aspire::Object::Factory)

    the data object factory

  • json (Hash) (defaults to: nil)

    the user profile data from the Aspire JSON API

  • ld (Hash) (defaults to: nil)

    the user profile data from the Aspire linked data API



29
30
31
32
33
34
35
36
# File 'lib/aspire/object/user.rb', line 29

def initialize(uri, factory, json: nil, ld: nil)
  super(uri, factory)
  json ||= {}
  self.email = json['email']
  self.first_name = json['firstName']
  self.role = json['role']
  self.surname = json['surname']
end

Instance Attribute Details

#emailArray<String>

Returns the list of email addresses for the user.

Returns:

  • (Array<String>)

    the list of email addresses for the user



9
10
11
# File 'lib/aspire/object/user.rb', line 9

def email
  @email
end

#first_nameString

Returns the user’s first name.

Returns:

  • (String)

    the user’s first name



13
14
15
# File 'lib/aspire/object/user.rb', line 13

def first_name
  @first_name
end

#roleArray<String>

Returns the Aspire roles associated with the user.

Returns:

  • (Array<String>)

    the Aspire roles associated with the user



17
18
19
# File 'lib/aspire/object/user.rb', line 17

def role
  @role
end

#surnameString

Returns the user’s last name.

Returns:

  • (String)

    the user’s last name



21
22
23
# File 'lib/aspire/object/user.rb', line 21

def surname
  @surname
end

Instance Method Details

#to_sString

Returns a string representation of the user profile (name and emails)

Returns:

  • (String)

    the string representation of the user profile



40
41
42
43
# File 'lib/aspire/object/user.rb', line 40

def to_s
  emails = email.nil? || email.empty? ? '' : " <#{email.join('; ')}>"
  "#{first_name} #{surname}#{emails}"
end