Class: LearnSprout::Term
- Inherits:
-
Object
- Object
- LearnSprout::Term
- Defined in:
- lib/learnsprout/term.rb
Instance Attribute Summary collapse
-
#end_date ⇒ Object
Returns the value of attribute end_date.
-
#name ⇒ Object
Returns the value of attribute name.
-
#school_id ⇒ Object
Returns the value of attribute school_id.
-
#start_date ⇒ Object
Returns the value of attribute start_date.
-
#term_id ⇒ Object
Returns the value of attribute term_id.
-
#time_updated ⇒ Object
Returns the value of attribute time_updated.
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Term
constructor
A new instance of Term.
-
#sections ⇒ Object
Gets the sections for this term.
Constructor Details
#initialize(attrs = {}) ⇒ Term
Returns a new instance of Term.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/learnsprout/term.rb', line 11 def initialize(attrs={}) @client = attrs["client"] @org_id = attrs["org_id"] @term_id = attrs["id"] @name = attrs["name"] @end_date = attrs["end_date"] && Date.parse(attrs["end_date"]) @start_date = attrs["start_date"] && Date.parse(attrs["start_date"]) @school_id = attrs["school_id"] @time_updated = attrs["time_updated"] @section_ids = [] if attrs["sections"] attrs["sections"].each do |section| @section_ids.push section["id"] end end end |
Instance Attribute Details
#end_date ⇒ Object
Returns the value of attribute end_date.
4 5 6 |
# File 'lib/learnsprout/term.rb', line 4 def end_date @end_date end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/learnsprout/term.rb', line 4 def name @name end |
#school_id ⇒ Object
Returns the value of attribute school_id.
4 5 6 |
# File 'lib/learnsprout/term.rb', line 4 def school_id @school_id end |
#start_date ⇒ Object
Returns the value of attribute start_date.
4 5 6 |
# File 'lib/learnsprout/term.rb', line 4 def start_date @start_date end |
#term_id ⇒ Object
Returns the value of attribute term_id.
4 5 6 |
# File 'lib/learnsprout/term.rb', line 4 def term_id @term_id end |
#time_updated ⇒ Object
Returns the value of attribute time_updated.
4 5 6 |
# File 'lib/learnsprout/term.rb', line 4 def time_updated @time_updated end |
Instance Method Details
#sections ⇒ Object
Gets the sections for this term. This method is extremely slow as it retrieves a list of IDs for associated terms then performs a separate request for each term for each ID.
TODO Optimize somehow, perhaps by lazy loading
32 33 34 35 36 37 38 39 40 |
# File 'lib/learnsprout/term.rb', line 32 def sections temp_sections = [] if @section_ids.count > 0 @section_ids.each do |section_id| temp_sections.push @client.section(@org_id, section_id) end end return temp_sections end |