Class: Aspire::Object::TimePeriod

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

Overview

Represents the time period covered by a reading list 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) ⇒ TimePeriod

Initialises a new TimePeriod instance



24
25
26
27
28
29
30
31
# File 'lib/aspire/object/time_period.rb', line 24

def initialize(uri, factory, json: nil, ld: nil)
  super(uri, factory)
  json ||= {}
  self.active = get_property('active', json)
  self.end_date = get_date('endDate', json)
  self.start_date = get_date('startDate', json)
  self.title = get_property('title', json)
end

Instance Attribute Details

#activeBoolean

Returns true if the time period is currently active.

Returns:

  • (Boolean)

    true if the time period is currently active



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

def active
  @active
end

#end_dateDate

Returns the end of the time period.

Returns:

  • (Date)

    the end of the time period



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

def end_date
  @end_date
end

#start_dateDate

Returns the start of the time period.

Returns:

  • (Date)

    the start of the time period



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

def start_date
  @start_date
end

#titleString

Returns the title of the time period.

Returns:

  • (String)

    the title of the time period



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

def title
  @title
end

Instance Method Details

#to_sString

Returns a string representation of the TimePeriod instance (the title)

Returns:

  • (String)

    the string representation of the TimePeriod instance



35
36
37
# File 'lib/aspire/object/time_period.rb', line 35

def to_s
  title.to_s
end

#yearInteger?

Returns the academic year containing this time period

Returns:

  • (Integer, nil)

    the academic year, or nil if unspecified



41
42
43
44
# File 'lib/aspire/object/time_period.rb', line 41

def year
  result = title.split('-')[0]
  result ? result.to_i : nil
end