Class: KielcePlugins::Schedule::Assignment

Inherits:
Object
  • Object
show all
Defined in:
lib/kielce_plugins/schedule/assignment.rb

Constant Summary collapse

ASSIGNMENT_KEYS =
[:id, :title, :type, :number, :link, :details]
SHORT_TYPE =
{
  homework: 'HW',
  project: 'P',
  lab: 'L'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row) ⇒ Assignment

Returns a new instance of Assignment.



19
20
21
# File 'lib/kielce_plugins/schedule/assignment.rb', line 19

def initialize(row)
  ASSIGNMENT_KEYS.each { |key| instance_variable_set "@#{key.to_s}".to_sym, row[key] }
end

Instance Attribute Details

#assignedObject

Returns the value of attribute assigned.



17
18
19
# File 'lib/kielce_plugins/schedule/assignment.rb', line 17

def assigned
  @assigned
end

#dueObject

Returns the value of attribute due.



17
18
19
# File 'lib/kielce_plugins/schedule/assignment.rb', line 17

def due
  @due
end

Instance Method Details

#has_type?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/kielce_plugins/schedule/assignment.rb', line 23

def has_type?
  !@type.nil?
end

#short_typeObject



31
32
33
34
35
36
# File 'lib/kielce_plugins/schedule/assignment.rb', line 31

def short_type
  return '' unless has_type?
  key = @type.downcase.to_sym
  $stderr.puts "Unknown type #{@type}" unless SHORT_TYPE.has_key?(key)
  SHORT_TYPE[key]
end

#title(style = :original, linked = false) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/kielce_plugins/schedule/assignment.rb', line 38

def title(style = :original, linked=false)
  case style
  when :original
    text = @title
  when :short_type
    type_num = has_type? ? "#{short_type}#{@number}: " : ''
    text = "#{type_num}#{@title}"
  when :full
    type_string = has_type? ? "#{@type} #{@number}: " : ''
    text = "#{type_string}#{@title}"
  else
    $stderr.puts "Unknown style #{sytle}"
    text = nil
  end

  # build a link, if a link provided
  (linked && !@link.nil?) ?  "<a target='_blank' href='#{@link}'>#{text}</a>" : text
end

#typeObject



27
28
29
# File 'lib/kielce_plugins/schedule/assignment.rb', line 27

def type
  @type.to_s
end