class CurriculumGenerator::Curriculum
Attributes
compiler[RW]
data_loader[RW]
data_pth[RW]
langs[RW]
master_lang[RW]
Public Class Methods
new(data_loader, compiler, data_pth, template_pth, langs=[], master_lang=nil)
click to toggle source
# File lib/curriculum-generator/curriculum.rb, line 6 def initialize(data_loader, compiler, data_pth, template_pth, langs=[], master_lang=nil) # Preconditions raise 'Invalid langs. It cannot be empty' if langs.empty? @data_loader = data_loader @compiler = compiler @langs = {} # If the master language is not provided, then defaults to the first # provided language. @master_lang = master_lang.nil? ? langs[0] : master_lang @data_pth = data_pth @template_pth = template_pth puts "> Picking up the available languages.".green langs.each do |lang| lang_data_pth = @data_pth.join(lang.to_s) inst = self Either.chain do bind -> { lang_data_pth.directory? } bind -> { lang_data = inst.data_loader.load_data( inst.data_pth, lang.to_sym, inst.master_lang.to_sym) lang_data.is_a?(Hash) ? Success(lang_data) : Failure("lang data") } bind ->(lang_data) { inst.langs[lang.to_sym] = { data: lang_data } } end end end
Public Instance Methods
compile(langs)
click to toggle source
Compile the curriculum for the provided languages.
# File lib/curriculum-generator/curriculum.rb, line 45 def compile(langs) puts ">> Compiling the curriculum for the languages: " \ "`#{langs.join(" ").light_black}`.".green # TODO: Refactor into monads, with better error detection. if langs.respond_to?(:each) langs.each do |lang| lang = lang.to_sym @compiler.compile(@langs[lang][:data], @template_pth, lang) end elsif @langs.include? langs @compiler.compile(@langs[lang][:data], @template_pth, langs) else raise "Invalid language." end end
validate_deps(template_deps_file_pth)
click to toggle source
# File lib/curriculum-generator/curriculum.rb, line 40 def validate_deps(template_deps_file_pth) @compiler.validate_deps template_deps_file_pth end