Class: CurriculumGenerator::Curriculum
- Inherits:
-
Object
- Object
- CurriculumGenerator::Curriculum
- Defined in:
- lib/curriculum-generator/curriculum.rb
Instance Attribute Summary collapse
-
#compiler ⇒ Object
Returns the value of attribute compiler.
-
#data_loader ⇒ Object
Returns the value of attribute data_loader.
-
#data_pth ⇒ Object
Returns the value of attribute data_pth.
-
#langs ⇒ Object
Returns the value of attribute langs.
-
#master_lang ⇒ Object
Returns the value of attribute master_lang.
Instance Method Summary collapse
-
#compile(langs) ⇒ Object
Compile the curriculum for the provided languages.
-
#initialize(data_loader, compiler, data_pth, template_pth, langs = [], master_lang = nil) ⇒ Curriculum
constructor
A new instance of Curriculum.
- #validate_deps(template_deps_file_pth) ⇒ Object
Constructor Details
#initialize(data_loader, compiler, data_pth, template_pth, langs = [], master_lang = nil) ⇒ Curriculum
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# 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 |
Instance Attribute Details
#compiler ⇒ Object
Returns the value of attribute compiler.
4 5 6 |
# File 'lib/curriculum-generator/curriculum.rb', line 4 def compiler @compiler end |
#data_loader ⇒ Object
Returns the value of attribute data_loader.
4 5 6 |
# File 'lib/curriculum-generator/curriculum.rb', line 4 def data_loader @data_loader end |
#data_pth ⇒ Object
Returns the value of attribute data_pth.
4 5 6 |
# File 'lib/curriculum-generator/curriculum.rb', line 4 def data_pth @data_pth end |
#langs ⇒ Object
Returns the value of attribute langs.
4 5 6 |
# File 'lib/curriculum-generator/curriculum.rb', line 4 def langs @langs end |
#master_lang ⇒ Object
Returns the value of attribute master_lang.
4 5 6 |
# File 'lib/curriculum-generator/curriculum.rb', line 4 def master_lang @master_lang end |
Instance Method Details
#compile(langs) ⇒ Object
Compile the curriculum for the provided languages.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# 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) ⇒ Object
40 41 42 |
# File 'lib/curriculum-generator/curriculum.rb', line 40 def validate_deps(template_deps_file_pth) @compiler.validate_deps template_deps_file_pth end |