Class: LessonsIndexer::Indexer

Inherits:
Messenger show all
Includes:
Addons::FileManager, Addons::GitManager
Defined in:
lib/lessons_indexer/indexer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Indexer

Returns a new instance of Indexer.



8
9
10
# File 'lib/lessons_indexer/indexer.rb', line 8

def initialize(options)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#add_headings(course) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/lessons_indexer/indexer.rb', line 35

def add_headings(course)
  course.load_lessons!
  course.load_headings!
  with_messages(pou('heading.starting'), pou('heading.done', title: course.title)) do
    course.generate_headings { |heading_line, lesson_file| prepend!(heading_line, lesson_file) }
  end
end

#build_index(course) ⇒ Object



28
29
30
31
32
33
# File 'lib/lessons_indexer/indexer.rb', line 28

def build_index(course)
  course.load_lessons!
  with_messages(pou('index.starting'), pou('index.done', title: course.title)) do
    write! course.generate_index, options.output
  end
end

#do_work!Object



12
13
14
15
16
17
18
19
20
# File 'lib/lessons_indexer/indexer.rb', line 12

def do_work!
  course = Course.new(get_course_dir, options.headings_dir)

  generate_files(course) if options.lessons.length > 0
  build_index(course) unless options.skip_index
  add_headings(course) if options.headings
  generate_pdfs(course) if options.pdf
  git_push! if options.git
end

#generate_files(course) ⇒ Object



22
23
24
25
26
# File 'lib/lessons_indexer/indexer.rb', line 22

def generate_files(course)
  with_messages(pou('lessons.starting'), pou('lessons.done', title: course.title)) do
    course.generate_files(options.lessons)
  end
end

#generate_pdfs(course) ⇒ Object



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

def generate_pdfs(course)
  course.load_lessons!
  with_messages(pou('pdf.starting'), pou('pdf.done', title: course.title)) do
    course.generate_pdfs
  end
end

#get_course_dirObject



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

def get_course_dir
  dir = Dir.entries('.').detect {|el| el =~ /_handouts\z/i}
  exit_msg(pou('errors.files_not_found')) if dir.nil?
  dir
end