Class: LUSI::API::Organisation::Unit

Inherits:
Object
  • Object
show all
Defined in:
lib/lusi_api/organisation.rb

Overview

Represents a single unit (component) of an Organisation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml = nil, lookup = nil, type: nil, hierarchy: nil, parent: nil, identity: nil, in_use: nil, is_academic: nil, mnemonic: nil, talis_code: nil, title: nil) ⇒ Unit

Initialises a new Unit instance If the hierarchy definition for the unit type specifies child units, the child unit instances are recursively created and added to the @children attribute.

Parameters:

  • xml (Nokogiri::XML::Document, Nokogiri::XML::Node) (defaults to: nil)

    the XML root of the unit from the LUSI API call

  • lookup (LUSI::API::Core::Lookup::LookupService, nil) (defaults to: nil)

    the lookup service for object resolution

  • type (Symbol) (defaults to: nil)

    the unit type

  • hierarchy (Hash) (defaults to: nil)

    the organisation’s hierarchy definition @see LUSI::API::Organisation::Organisation::HIERARCHY

  • parent (Unit, nil) (defaults to: nil)

    the parent Unit of this unit, or nil for a top-level unit

  • identity (any, nil) (defaults to: nil)

    the default identity code

  • in_use (Boolean, nil) (defaults to: nil)

    the default in-use flag value

  • is_academic (Boolean, nil) (defaults to: nil)

    the default is-academic flag value

  • mnemonic (any, nil) (defaults to: nil)

    the default mnemonic code

  • talis_code (any, nil) (defaults to: nil)

    the default Talis code

  • title (any, nil) (defaults to: nil)

    the default unit title (name)



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/lusi_api/organisation.rb', line 256

def initialize(xml = nil, lookup = nil, type: nil, hierarchy: nil, parent: nil, identity: nil, in_use: nil,
               is_academic: nil, mnemonic: nil, talis_code: nil, title: nil)
  
  @identity = LUSI::API::Core::XML.xml_content_at(xml, 'xmlns:Identity', identity)
  @in_use = LUSI::API::Core::XML.xml_boolean_at(xml, 'xmlns:InUse', in_use)
  @is_academic = LUSI::API::Core::XML.xml_boolean_at(xml, 'xmlns:IsAcademic', is_academic)
  @mnemonic = LUSI::API::Core::XML.xml_content_at(xml, 'xmlns:Mnemonic', mnemonic)
  @parent = parent
  @talis_code = LUSI::API::Core::XML.xml_content_at(xml, 'xmlns:TalisCode', talis_code)
  @title = LUSI::API::Core::XML.xml_content_at(xml, 'xmlns:Title', title)
  @type = type
  
  # Get the child units of this unit
  # If a block is given, yield each child to the block
  child = hierarchy ? hierarchy[type] : nil
  if child
    @children = LUSI::API::Core::XML.xml(xml, child[:path]) do |u|
      Unit.new(u, lookup, type: child[:type], parent: self, hierarchy: hierarchy)
    end
  else
    @children = nil
  end
  
end

Instance Attribute Details

#childrenArray<Unit>?

Returns an array of child Unit instances.

Returns:

  • (Array<Unit>, nil)

    an array of child Unit instances



215
216
217
# File 'lib/lusi_api/organisation.rb', line 215

def children
  @children
end

#identityany?

Returns the identity code of the unit.

Returns:

  • (any, nil)

    the identity code of the unit



218
219
220
# File 'lib/lusi_api/organisation.rb', line 218

def identity
  @identity
end

#in_useBoolean?

Returns true if the unit is currently in use, or false if historic.

Returns:

  • (Boolean, nil)

    true if the unit is currently in use, or false if historic



221
222
223
# File 'lib/lusi_api/organisation.rb', line 221

def in_use
  @in_use
end

#is_academicBoolean?

Returns true if the unit is an academic unit, or false if not (e.g. administrative).

Returns:

  • (Boolean, nil)

    true if the unit is an academic unit, or false if not (e.g. administrative)



224
225
226
# File 'lib/lusi_api/organisation.rb', line 224

def is_academic
  @is_academic
end

#mnemonicString?

Returns a short mnemonic code for the unit.

Returns:

  • (String, nil)

    a short mnemonic code for the unit



227
228
229
# File 'lib/lusi_api/organisation.rb', line 227

def mnemonic
  @mnemonic
end

#parentUnit?

Returns the parent of this unit in the organisation hierarchy, or nil if this is a top-level unit.

Returns:

  • (Unit, nil)

    the parent of this unit in the organisation hierarchy, or nil if this is a top-level unit



230
231
232
# File 'lib/lusi_api/organisation.rb', line 230

def parent
  @parent
end

#talis_codeString?

Returns the code for this unit used by Talis Aspire reading lists.

Returns:

  • (String, nil)

    the code for this unit used by Talis Aspire reading lists



233
234
235
# File 'lib/lusi_api/organisation.rb', line 233

def talis_code
  @talis_code
end

#titleString?

Returns the title (name) of the unit.

Returns:

  • (String, nil)

    the title (name) of the unit



236
237
238
# File 'lib/lusi_api/organisation.rb', line 236

def title
  @title
end

#typeSymbol?

Returns the type of the unit (e.g. :institution, :faculty, :department).

Returns:

  • (Symbol, nil)

    the type of the unit (e.g. :institution, :faculty, :department)



239
240
241
# File 'lib/lusi_api/organisation.rb', line 239

def type
  @type
end

Instance Method Details

#to_sObject

Returns a string representation of the unit



282
283
284
# File 'lib/lusi_api/organisation.rb', line 282

def to_s
  "#{@type}: #{@title}"
end