Class: Mumukit::Sync::Store::Github::GuideWriter
- Inherits:
-
Object
- Object
- Mumukit::Sync::Store::Github::GuideWriter
- Defined in:
- lib/mumukit/sync/store/github/guide_writer.rb
Instance Attribute Summary collapse
-
#dir ⇒ Object
Returns the value of attribute dir.
Instance Method Summary collapse
- #format_id(guide, exercise) ⇒ Object
-
#initialize(dir) ⇒ GuideWriter
constructor
A new instance of GuideWriter.
- #write_exercise!(guide, e) ⇒ Object
- #write_file_fields!(base_path, schema, element, language) ⇒ Object
- #write_guide!(guide) ⇒ Object
- #write_licenses!(guide) ⇒ Object
- #write_metadata_fields!(base_path, schema, e) ⇒ Object
Constructor Details
#initialize(dir) ⇒ GuideWriter
Returns a new instance of GuideWriter.
5 6 7 |
# File 'lib/mumukit/sync/store/github/guide_writer.rb', line 5 def initialize(dir) @dir = dir end |
Instance Attribute Details
#dir ⇒ Object
Returns the value of attribute dir.
3 4 5 |
# File 'lib/mumukit/sync/store/github/guide_writer.rb', line 3 def dir @dir end |
Instance Method Details
#format_id(guide, exercise) ⇒ Object
33 34 35 |
# File 'lib/mumukit/sync/store/github/guide_writer.rb', line 33 def format_id(guide, exercise) guide[:id_format] % exercise[:id] end |
#write_exercise!(guide, e) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/mumukit/sync/store/github/guide_writer.rb', line 37 def write_exercise!(guide, e) dirname = File.join dir, to_fs_friendly_name("#{format_id(guide, e)}_#{e[:name]}") FileUtils.mkdir_p dirname dirname, Mumukit::Sync::Store::Github::Schema::Exercise, e write_file_fields! dirname, Mumukit::Sync::Store::Github::Schema::Exercise, e, (e[:language] || guide[:language]) end |
#write_file_fields!(base_path, schema, element, language) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/mumukit/sync/store/github/guide_writer.rb', line 9 def write_file_fields!(base_path, schema, element, language) schema.file_fields.each do |it| file_name = it.get_file_name(language) write_file! base_path, file_name, it.get_field_value(element) if it.field_value_present?(element) end end |
#write_guide!(guide) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/mumukit/sync/store/github/guide_writer.rb', line 23 def write_guide!(guide) guide[:exercises].each do |e| write_exercise! guide, e end write_licenses!(guide) dir, Mumukit::Sync::Store::Github::Schema::Guide, guide write_file_fields! dir, Mumukit::Sync::Store::Github::Schema::Guide, guide, guide[:language] end |
#write_licenses!(guide) ⇒ Object
46 47 48 49 50 |
# File 'lib/mumukit/sync/store/github/guide_writer.rb', line 46 def write_licenses!(guide) write_file! dir, 'COPYRIGHT.txt', copyright_content(guide) write_file! dir, 'README.md', readme_content(guide) copy_file! 'LICENSE.txt' end |
#write_metadata_fields!(base_path, schema, e) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/mumukit/sync/store/github/guide_writer.rb', line 16 def (base_path, schema, e) = schema..map do |field| [field.name.to_s, field.get_field_value(e)] end.to_h.compact.merge('name' => e[:name]).to_yaml write_file! base_path, 'meta.yml', end |