Class: Mo2tex::Course

Inherits:
Object
  • Object
show all
Includes:
CourseHelper
Defined in:
lib/mo2tex/course.rb

Direct Known Subclasses

CollectiveCourse, IndividualCourse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CourseHelper

#normalize_title

Constructor Details

#initialize(title, desc, exmgr) ⇒ Course

Returns a new instance of Course.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mo2tex/course.rb', line 15

def initialize(title, desc, exmgr)
    @warnings = {}
    @hours_done = 0
    @excl_mgr = exmgr
    self.excl_mgr << desc['exclude'] if desc.has_key?('exclude')
	@title = normalize_title(title)
	@hours = desc['ore']
	@type  = desc['tipologia']
    @real_type = desc['tip_effettiva']
	@students = desc['studenti']
    @students_fc = desc['studenti_fc']
	@start = DateTime.parse(desc['inizio'].to_s)
    @freq  = parse_frequency(desc['frequenza'])
    @wday  = desc['giorno']
    @dur   = parse_dur(desc['durata_lezione']) # beware! YAML converts in seconds!
    @when  = parse_dur(desc['orario'])         # beware! YAML converts in seconds!
    @where = 'aula ' + desc['aula']
    @online = desc['online']
    @events = generate_events
end

Instance Attribute Details

#durObject (readonly)

Returns the value of attribute dur.



11
12
13
# File 'lib/mo2tex/course.rb', line 11

def dur
  @dur
end

#eventsObject (readonly)

Returns the value of attribute events.



11
12
13
# File 'lib/mo2tex/course.rb', line 11

def events
  @events
end

#excl_mgrObject (readonly)

Returns the value of attribute excl_mgr.



11
12
13
# File 'lib/mo2tex/course.rb', line 11

def excl_mgr
  @excl_mgr
end

#freqObject (readonly)

Returns the value of attribute freq.



11
12
13
# File 'lib/mo2tex/course.rb', line 11

def freq
  @freq
end

#hoursObject (readonly)

Returns the value of attribute hours.



11
12
13
# File 'lib/mo2tex/course.rb', line 11

def hours
  @hours
end

#hours_doneObject (readonly)

Returns the value of attribute hours_done.



11
12
13
# File 'lib/mo2tex/course.rb', line 11

def hours_done
  @hours_done
end

#onlineObject (readonly)

Returns the value of attribute online.



11
12
13
# File 'lib/mo2tex/course.rb', line 11

def online
  @online
end

#real_typeObject (readonly)

Returns the value of attribute real_type.



11
12
13
# File 'lib/mo2tex/course.rb', line 11

def real_type
  @real_type
end

#startObject (readonly)

Returns the value of attribute start.



11
12
13
# File 'lib/mo2tex/course.rb', line 11

def start
  @start
end

#studentsObject (readonly)

Returns the value of attribute students.



11
12
13
# File 'lib/mo2tex/course.rb', line 11

def students
  @students
end

#students_fcObject (readonly)

Returns the value of attribute students_fc.



11
12
13
# File 'lib/mo2tex/course.rb', line 11

def students_fc
  @students_fc
end

#titleObject (readonly)

Returns the value of attribute title.



11
12
13
# File 'lib/mo2tex/course.rb', line 11

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



11
12
13
# File 'lib/mo2tex/course.rb', line 11

def type
  @type
end

#warningsObject (readonly)

Returns the value of attribute warnings.



11
12
13
# File 'lib/mo2tex/course.rb', line 11

def warnings
  @warnings
end

#wdayObject (readonly)

Returns the value of attribute wday.



11
12
13
# File 'lib/mo2tex/course.rb', line 11

def wday
  @wday
end

#whenObject (readonly)

Returns the value of attribute when.



11
12
13
# File 'lib/mo2tex/course.rb', line 11

def when
  @when
end

#whereObject (readonly)

Returns the value of attribute where.



11
12
13
# File 'lib/mo2tex/course.rb', line 11

def where
  @where
end

Class Method Details

.create(title, desc, exm) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/mo2tex/course.rb', line 60

def create(title, desc, exm)
	result = nil
	case desc['tip_effettiva']
		when 'collettiva'
			result = CollectiveCourse.new(title, desc, exm)
		when 'individuale'
			result = IndividualCourse.new(title, desc, exm)
		else
			raise UnknownCourseType, "Unknown type #{desc['tipologia']}"
	end
	return result
end

Instance Method Details

#academic_hoursObject



84
85
86
# File 'lib/mo2tex/course.rb', line 84

def academic_hours
	return self.total_hours
end

#all_studentsObject



88
89
90
# File 'lib/mo2tex/course.rb', line 88

def all_students
  return self.students + ' ' + self.students_fc
end

#course_dur_in_secondsObject



45
46
47
# File 'lib/mo2tex/course.rb', line 45

def course_dur_in_seconds
	return self.academic_hours * 3600
end

#generate(&block) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/mo2tex/course.rb', line 36

def generate(&block)
  result = ''
  self.events.each do
    |ev|
    result += yield(self.title, self.number_of_lessons, ev)
  end
  return result
end

#hours_done_per_lesson(dts, dte) ⇒ Object

Raises:

  • (PureVirtualMethodCalled)


92
93
94
# File 'lib/mo2tex/course.rb', line 92

def hours_done_per_lesson(dts, dte)
			raise PureVirtualMethodCalled, 'Course#hours_done_per_lesson'
end

#lesson_dur_in_secondsObject



49
50
51
# File 'lib/mo2tex/course.rb', line 49

def lesson_dur_in_seconds
  return ((self.dur * 24)*3600).round.to_i
end

#num_studentsObject



75
76
77
78
# File 'lib/mo2tex/course.rb', line 75

def num_students
    split_studs = self.students.split(/, */)
	return split_studs.size
end

#number_of_lessonsObject



53
54
55
56
# File 'lib/mo2tex/course.rb', line 53

def number_of_lessons
    result = (self.course_dur_in_seconds.to_f / self.lesson_dur_in_seconds.to_f).round.to_i
    return result
end

#total_hoursObject

Raises:

  • (PureVirtualMethodCalled)


80
81
82
# File 'lib/mo2tex/course.rb', line 80

def total_hours
	raise PureVirtualMethodCalled, 'Course#total_hours'
end