Class: LearnSprout::Term

Inherits:
Object
  • Object
show all
Defined in:
lib/learnsprout/term.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_dateObject

Returns the value of attribute end_date.



4
5
6
# File 'lib/learnsprout/term.rb', line 4

def end_date
  @end_date
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/learnsprout/term.rb', line 4

def name
  @name
end

#school_idObject

Returns the value of attribute school_id.



4
5
6
# File 'lib/learnsprout/term.rb', line 4

def school_id
  @school_id
end

#start_dateObject

Returns the value of attribute start_date.



4
5
6
# File 'lib/learnsprout/term.rb', line 4

def start_date
  @start_date
end

#term_idObject

Returns the value of attribute term_id.



4
5
6
# File 'lib/learnsprout/term.rb', line 4

def term_id
  @term_id
end

#time_updatedObject

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

#sectionsObject

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