Class: Verso::TaskList

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

Overview

Task List resource

A collection of DutyArea objects containing the Task objects for 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

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



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
# File 'lib/verso/task_list.rb', line 18

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

  # @return [Boolean] Contains non-essential tasks?
  def has_optional_task?
    any? { |da| da.tasks.any? { |t| !t.essential } }
  end

  # @return [Boolean] Contains sensitive tasks?
  def has_sensitive_task?
    any? { |da| da.tasks.any? { |t| t.sensitive } }
  end

private

  def duty_areas
    @duty_areas ||= begin
                      get_attr(:duty_areas).
                        collect do |da|
                          DutyArea.new(
                            da.merge!(:code => code, :edition => edition)
                          )
                        end
                    rescue NameError, Verso::ResourceNotFoundError
                      []
                    end
  end

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

#editionString (readonly)

Returns Course edition.

Returns:

  • (String)

    Course edition



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
# File 'lib/verso/task_list.rb', line 18

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

  # @return [Boolean] Contains non-essential tasks?
  def has_optional_task?
    any? { |da| da.tasks.any? { |t| !t.essential } }
  end

  # @return [Boolean] Contains sensitive tasks?
  def has_sensitive_task?
    any? { |da| da.tasks.any? { |t| t.sensitive } }
  end

private

  def duty_areas
    @duty_areas ||= begin
                      get_attr(:duty_areas).
                        collect do |da|
                          DutyArea.new(
                            da.merge!(:code => code, :edition => edition)
                          )
                        end
                    rescue NameError, Verso::ResourceNotFoundError
                      []
                    end
  end

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

Instance Method Details

#has_optional_task?Boolean

Returns Contains non-essential tasks?.

Returns:

  • (Boolean)

    Contains non-essential tasks?



26
27
28
# File 'lib/verso/task_list.rb', line 26

def has_optional_task?
  any? { |da| da.tasks.any? { |t| !t.essential } }
end

#has_sensitive_task?Boolean

Returns Contains sensitive tasks?.

Returns:

  • (Boolean)

    Contains sensitive tasks?



31
32
33
# File 'lib/verso/task_list.rb', line 31

def has_sensitive_task?
  any? { |da| da.tasks.any? { |t| t.sensitive } }
end