Sha256: 5c74c3dd83c973f03eb14b5e5f8f0bc32acd2c9c80c5cfd1c611ce58dedbbb88

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

class Exercism
  class Assignment

    def self.save(data, path)
      assignments = []
      data['assignments'].each do |attributes|
        assignments << Assignment.new(attributes.merge('project_dir' => path)).save
      end
      assignments
    end

    attr_reader :track, :slug, :readme, :test_file, :tests, :project_dir

    def initialize(attributes)
      @track = attributes['track']
      @slug = attributes['slug']
      @readme = attributes['readme']
      @test_file = attributes['test_file']
      @tests = attributes['tests']
      @project_dir = attributes['project_dir']
    end

    def save
      FileUtils.mkdir_p assignment_dir
      save_readme
      save_tests unless File.exist?(tests_path)
      self
    end

    def save_readme
      File.open readme_path, 'w' do |f|
        f.write readme
      end
    end

    def save_tests
      File.open tests_path, 'w' do |f|
        f.write tests
      end
    end

    def assignment_dir
      @assignment_dir ||= File.join(project_dir, track, slug)
    end

    private

    def readme_path
      File.join(assignment_dir, 'README.md')
    end

    def tests_path
      File.join(assignment_dir, test_file)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
exercism-0.0.12 lib/exercism/assignment.rb
exercism-0.0.11 lib/exercism/assignment.rb
exercism-0.0.10 lib/exercism/assignment.rb