Class: LessonsIndexer::Course

Inherits:
Messenger show all
Includes:
Collections, Models
Defined in:
lib/lessons_indexer/course.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(course_dir, headings_dir) ⇒ Course

Returns a new instance of Course.



8
9
10
11
12
13
# File 'lib/lessons_indexer/course.rb', line 8

def initialize(course_dir, headings_dir)
  @dir = course_dir
  @headings_dir = headings_dir
  @title = dir.gsub(/_handouts\z/i, '').titlecase
  @headings = []
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



6
7
8
# File 'lib/lessons_indexer/course.rb', line 6

def dir
  @dir
end

#headingsObject (readonly)

Returns the value of attribute headings.



6
7
8
# File 'lib/lessons_indexer/course.rb', line 6

def headings
  @headings
end

#headings_dirObject (readonly)

Returns the value of attribute headings_dir.



6
7
8
# File 'lib/lessons_indexer/course.rb', line 6

def headings_dir
  @headings_dir
end

#lessonsObject (readonly)

Returns the value of attribute lessons.



6
7
8
# File 'lib/lessons_indexer/course.rb', line 6

def lessons
  @lessons
end

#titleObject (readonly)

Returns the value of attribute title.



6
7
8
# File 'lib/lessons_indexer/course.rb', line 6

def title
  @title
end

Instance Method Details

#generate_files(lessons_count) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/lessons_indexer/course.rb', line 15

def generate_files(lessons_count)
  within(dir, true) do
    lessons_count.map {|l| Integer(l)}.each_with_index do |steps, lesson|
      (1..steps).each do |step|
        File.new("lesson#{lesson + 1}-#{step}.md", 'w+').close
      end
    end
  end
end

#generate_headingsObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/lessons_indexer/course.rb', line 31

def generate_headings
  lessons.each do |lesson|
    lesson_heading = headings.for(lesson)
    if lesson_heading
      yield "![](#{headings_dir}/#{lesson_heading.file_name})\n\n", lesson.path
    else
      warning pou('warnings.heading_not_found', lesson: lesson.name)
    end
  end
end

#generate_indexObject



25
26
27
28
29
# File 'lib/lessons_indexer/course.rb', line 25

def generate_index
  lessons.list.sort.inject(pou('course.index_title', title: title)) do |memo, lesson|
    memo + lesson.link(dir)
  end
end

#generate_pdfsObject



42
43
44
45
46
47
48
# File 'lib/lessons_indexer/course.rb', line 42

def generate_pdfs
  within(dir, true) do
    lessons.list.sort.each do |lesson|
      %x{pandoc #{lesson.file_name} -f markdown_github -o #{lesson.file_name.gsub(/md\z/i, '')}pdf --variable geometry:"top=1.5cm, bottom=2.5cm, left=1.5cm, right=1.5cm" --latex-engine=xelatex --variable mainfont="Open Sans" --variable monofont="Liberation Mono" --variable fontsize="12pt"}
    end
  end
end

#load_headings!Object



50
51
52
53
54
# File 'lib/lessons_indexer/course.rb', line 50

def load_headings!
  within(dir + '/' + headings_dir, true) do
    @headings = HeadingsList.new(all_with_pattern(Heading::VERSION_PATTERN).map {|heading| Heading.new(heading)})
  end
end

#load_lessons!Object



56
57
58
59
60
# File 'lib/lessons_indexer/course.rb', line 56

def load_lessons!
  within(dir, true) do
    @lessons = LessonsList.new(all_with_pattern(Lesson::NAME_PATTERN).map {|lesson| Lesson.new(lesson)})
  end
end