class LUSI::API::Organisation::Unit

Represents a single unit (component) of an Organisation

Attributes

children[RW]

@!attribute [rw] children

@return [Array<Unit>, nil] an array of child Unit instances
identity[RW]

@!attribute [rw] identity

@return [any, nil] the identity code of the unit
in_use[RW]

@!attribute [rw] in_use

@return [Boolean, nil] true if the unit is currently in use, or false if historic
is_academic[RW]

@!attribute [rw] is_academic

@return [Boolean, nil] true if the unit is an academic unit, or false if not (e.g. administrative)
mnemonic[RW]

@!attribute [rw] mnemonic

@return [String, nil] a short mnemonic code for the unit
parent[RW]

@!attribute [rw] parent

@return [Unit, nil] the parent of this unit in the organisation hierarchy, or nil if this is a top-level unit
talis_code[RW]

@!attribute [rw] talis_code

@return [String, nil] the code for this unit used by Talis Aspire reading lists
title[RW]

@!attribute [rw] title

@return [String, nil] the title (name) of the unit
type[RW]

@!attribute [rw] type

@return [Symbol, nil] the type of the unit (e.g. :institution, :faculty, :department)

Public Class Methods

new(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) click to toggle source

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. @param xml [Nokogiri::XML::Document, Nokogiri::XML::Node] the XML root of the unit from the LUSI API call @param lookup [LUSI::API::Core::Lookup::LookupService, nil] the lookup service for object resolution @param type [Symbol] the unit type @param hierarchy [Hash] the organisation's hierarchy definition

@see LUSI::API::Organisation::Organisation::HIERARCHY

@param parent [Unit, nil] the parent Unit of this unit, or nil for a top-level unit @param identity [any, nil] the default identity code @param in_use [Boolean, nil] the default in-use flag value @param is_academic [Boolean, nil] the default is-academic flag value @param mnemonic [any, nil] the default mnemonic code @param talis_code [any, nil] the default Talis code @param title [any, nil] the default unit title (name)

# 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

Public Instance Methods

to_s() click to toggle source

Returns a string representation of the unit

# File lib/lusi_api/organisation.rb, line 282
def to_s
  "#{@type}: #{@title}"
end