Class: Aspire::Object::TimePeriod
- 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
Constants included from Util
Instance Attribute Summary collapse
-
#active ⇒ Boolean
True if the time period is currently active.
-
#end_date ⇒ Date
The end of the time period.
-
#start_date ⇒ Date
The start of the time period.
-
#title ⇒ String
The title of the time period.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(uri, factory, json: nil, ld: nil) ⇒ TimePeriod
constructor
Initialises a new TimePeriod instance.
-
#to_s ⇒ String
Returns a string representation of the TimePeriod instance (the title).
-
#year ⇒ Integer?
Returns the academic year containing this time period.
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
#active ⇒ Boolean
Returns 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_date ⇒ Date
Returns 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_date ⇒ Date
Returns the start of the time period.
17 18 19 |
# File 'lib/aspire/object/time_period.rb', line 17 def start_date @start_date end |
#title ⇒ String
Returns 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_s ⇒ String
Returns a string representation of the TimePeriod instance (the title)
35 36 37 |
# File 'lib/aspire/object/time_period.rb', line 35 def to_s title.to_s end |
#year ⇒ Integer?
Returns the academic year containing this time period
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 |