Class: Verso::StandardsList

Inherits:
Base
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable, HTTPGettable
Defined in:
lib/verso/standards_list.rb

Overview

Standards List resource

A collection of Standard objects correlated to a Course.

Note:

Attributes required:

Options Hash (attrs):

  • :code (String)

    Course code Required

  • :edition (String)

    Edition year Required

See Also:

Instance Attribute Summary collapse

Attributes inherited from Base

#attrs

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

attr_reader, #initialize

Constructor Details

This class inherits a constructor from Verso::Base

Instance Attribute Details

#codeString (readonly)

Returns Course code.

Returns:

  • (String)

    Course code



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/verso/standards_list.rb', line 17

class StandardsList < Verso::Base
  include Enumerable
  include HTTPGettable
  extend Forwardable
  def_delegators :standards, :[], :each, :empty?, :last, :length
  attr_reader :code, :edition

  # @return [Array] Non-SOL standards in this list
  def non_sols
    @non_sols ||= reject { |s| sol_titles.include?(s.title) }
  end

  # @return [Array] SOL standards in this list
  def sols
    @sols ||= select { |s| sol_titles.include?(s.title) }
  end

  # Find Standards by {Verso::Course}.
  #
  # @param course [Verso::Course] A {Verso::Course}
  # @return [Verso::StandardsList] A {Verso::Course}'s standards
  def self.from_course(course)
    if course.related_resources.include?("standards")
      StandardsList.new(:code => course.code, :edition => course.edition)
    else
      StandardsList.new(:code => course.code, :edition => course.edition,
                        :standards => [])
    end
  end

private

  def sol_titles
    ['English', 'History and Social Science', 'Mathematics', 'Science']
  end

  def standards
    @standards ||= get_attr(:standards).
      sort_by { |s| s[:title] }.
      collect do |raw_standard|
        Standard.new(raw_standard.merge(:code => code, :edition => edition))
      end
  end

  def path
    "/courses/#{code},#{edition}/standards/"
  end
end

#editionString (readonly)

Returns Course edition year.

Returns:

  • (String)

    Course edition year



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/verso/standards_list.rb', line 17

class StandardsList < Verso::Base
  include Enumerable
  include HTTPGettable
  extend Forwardable
  def_delegators :standards, :[], :each, :empty?, :last, :length
  attr_reader :code, :edition

  # @return [Array] Non-SOL standards in this list
  def non_sols
    @non_sols ||= reject { |s| sol_titles.include?(s.title) }
  end

  # @return [Array] SOL standards in this list
  def sols
    @sols ||= select { |s| sol_titles.include?(s.title) }
  end

  # Find Standards by {Verso::Course}.
  #
  # @param course [Verso::Course] A {Verso::Course}
  # @return [Verso::StandardsList] A {Verso::Course}'s standards
  def self.from_course(course)
    if course.related_resources.include?("standards")
      StandardsList.new(:code => course.code, :edition => course.edition)
    else
      StandardsList.new(:code => course.code, :edition => course.edition,
                        :standards => [])
    end
  end

private

  def sol_titles
    ['English', 'History and Social Science', 'Mathematics', 'Science']
  end

  def standards
    @standards ||= get_attr(:standards).
      sort_by { |s| s[:title] }.
      collect do |raw_standard|
        Standard.new(raw_standard.merge(:code => code, :edition => edition))
      end
  end

  def path
    "/courses/#{code},#{edition}/standards/"
  end
end

Class Method Details

.from_course(course) ⇒ Verso::StandardsList

Find Standards by Course.

Parameters:

Returns:



38
39
40
41
42
43
44
45
# File 'lib/verso/standards_list.rb', line 38

def self.from_course(course)
  if course.related_resources.include?("standards")
    StandardsList.new(:code => course.code, :edition => course.edition)
  else
    StandardsList.new(:code => course.code, :edition => course.edition,
                      :standards => [])
  end
end

Instance Method Details

#non_solsArray

Returns Non-SOL standards in this list.

Returns:

  • (Array)

    Non-SOL standards in this list



25
26
27
# File 'lib/verso/standards_list.rb', line 25

def non_sols
  @non_sols ||= reject { |s| sol_titles.include?(s.title) }
end

#solsArray

Returns SOL standards in this list.

Returns:

  • (Array)

    SOL standards in this list



30
31
32
# File 'lib/verso/standards_list.rb', line 30

def sols
  @sols ||= select { |s| sol_titles.include?(s.title) }
end