Class: LUSI::API::Organisation::Unit
- Inherits:
-
Object
- Object
- LUSI::API::Organisation::Unit
- Defined in:
- lib/lusi_api/organisation.rb
Overview
Represents a single unit (component) of an Organisation
Instance Attribute Summary collapse
-
#children ⇒ Array<Unit>?
An array of child Unit instances.
-
#identity ⇒ any?
The identity code of the unit.
-
#in_use ⇒ Boolean?
True if the unit is currently in use, or false if historic.
-
#is_academic ⇒ Boolean?
True if the unit is an academic unit, or false if not (e.g. administrative).
-
#mnemonic ⇒ String?
A short mnemonic code for the unit.
-
#parent ⇒ Unit?
The parent of this unit in the organisation hierarchy, or nil if this is a top-level unit.
-
#talis_code ⇒ String?
The code for this unit used by Talis Aspire reading lists.
-
#title ⇒ String?
The title (name) of the unit.
-
#type ⇒ Symbol?
The type of the unit (e.g. :institution, :faculty, :department).
Instance Method Summary collapse
-
#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
constructor
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.
-
#to_s ⇒ Object
Returns a string representation of the unit.
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.
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
#children ⇒ Array<Unit>?
Returns an array of child Unit instances.
215 216 217 |
# File 'lib/lusi_api/organisation.rb', line 215 def children @children end |
#identity ⇒ any?
Returns the identity code of the unit.
218 219 220 |
# File 'lib/lusi_api/organisation.rb', line 218 def identity @identity end |
#in_use ⇒ Boolean?
Returns 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_academic ⇒ Boolean?
Returns 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 |
#mnemonic ⇒ String?
Returns a short mnemonic code for the unit.
227 228 229 |
# File 'lib/lusi_api/organisation.rb', line 227 def mnemonic @mnemonic end |
#parent ⇒ Unit?
Returns 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_code ⇒ String?
Returns 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 |
#title ⇒ String?
Returns the title (name) of the unit.
236 237 238 |
# File 'lib/lusi_api/organisation.rb', line 236 def title @title end |
#type ⇒ Symbol?
Returns 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_s ⇒ Object
Returns a string representation of the unit
282 283 284 |
# File 'lib/lusi_api/organisation.rb', line 282 def to_s "#{@type}: #{@title}" end |