Class: LUSI::API::Calendar::Week

Inherits:
LUSI::API::Core::Code show all
Defined in:
lib/lusi_api/calendar.rb

Overview

Represents an academic week in the LUSI API

Instance Attribute Summary collapse

Attributes inherited from LUSI::API::Core::BasicCode

#description, #identity

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from LUSI::API::Core::BasicCode

#to_s

Constructor Details

#initialize(xml = nil, lookup = nil, term: nil, monday_date: nil, year: nil, att_identity: nil, **kwargs) ⇒ void

Initialises a new Week instance

Parameters:

  • att_identity (Integer, nil) (defaults to: nil)

    the default academic timetable (ATT) identity

  • monday_date (DateTime, nil) (defaults to: nil)

    the default Monday week-start date

  • term (String, nil) (defaults to: nil)

    the default term

  • year (LUSI::API::Calendar::Year, nil) (defaults to: nil)

    the default academic year



71
72
73
74
75
76
77
# File 'lib/lusi_api/calendar.rb', line 71

def initialize(xml = nil, lookup = nil, term: nil, monday_date: nil, year: nil, att_identity: nil, **kwargs)
  super(xml, lookup, **kwargs)
  @att_identity = LUSI::API::Core::XML.xml_int_at(xml, 'xmlns:ATTIdentity', att_identity)
  @monday_date = LUSI::API::Core::XML.xml_datetime_at(xml, 'xmlns:MondayDate', monday_date)
  @term = LUSI::API::Core::XML.xml_content_at(xml, 'xmlns:Term', term)
  @year = LUSI::API::Core::XML.lookup(xml, lookup, :year, 'xmlns:Year/xmlns:Identity', year)
end

Instance Attribute Details

#att_identityInteger?

Returns the academic timetable (ATT) week identity.

Returns:

  • (Integer, nil)

    the academic timetable (ATT) week identity



16
17
18
# File 'lib/lusi_api/calendar.rb', line 16

def att_identity
  @att_identity
end

#monday_dateDateTime?

Returns the Monday starting the week.

Returns:

  • (DateTime, nil)

    the Monday starting the week



20
21
22
# File 'lib/lusi_api/calendar.rb', line 20

def monday_date
  @monday_date
end

#termString?

Returns The term/period the week is in.

Returns:

  • (String, nil)

    The term/period the week is in



24
25
26
# File 'lib/lusi_api/calendar.rb', line 24

def term
  @term
end

#yearLUSI::API::Calendar::Year?

Returns the academic year containing the week.

Returns:



28
29
30
# File 'lib/lusi_api/calendar.rb', line 28

def year
  @year
end

Class Method Details

.get_current_academic_week(api = nil, lookup = nil) {|obj| ... } ⇒ LUSI::API::Calendar::Week

Returns a Week instance for the current academic week

Parameters:

Yields:

  • (obj)

    Passes the Week instance to the block

Yield Parameters:

Returns:



36
37
38
39
40
41
# File 'lib/lusi_api/calendar.rb', line 36

def self.get_current_academic_week(api = nil, lookup = nil)
  xml = api.call('LUSIReference', 'General.asmx', 'GetCurrentAcademicWeek')
  obj = new(LUSI::API::Core::XML.xml_at(xml, 'xmlns:Week'), lookup)
  yield(obj) if block_given?
  obj
end

.get_instance(api = nil, lookup = nil, use_lookup: true, year_identity: nil) {|obj| ... } ⇒ Array<LUSI::API::Calendar::Week>

Returns Week instances for all or one specific academic year

Parameters:

  • api (LUSI::API::Core::API) (defaults to: nil)

    the LUSI API instance

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

    the lookup service for object resolution

  • use_lookup (Boolean) (defaults to: true)

    if true, use the lookup service to identify instances before trying the API

  • year (LUSI::API::Calendar::Year, String, nil)

    the academic year required (all defined weeks if nil)

Yields:

  • (obj)

    Passes the Week instance to the block

Yield Parameters:

Returns:



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/lusi_api/calendar.rb', line 51

def self.get_instance(api = nil, lookup = nil, use_lookup: true, year_identity: nil)
  # Search the lookup service
  if lookup and use_lookup
    week = lookup.lookup(:week, year_identity)
    if week
      yield(week) if block_given?
      return week
    end
  end
  # Search the API
  super(api, lookup, 'LUSIReference', 'General.asmx', 'GetWeeks', 'xmlns:Week', year_identity: year_identity)
end