Sha256: 4f4fca410434f22bfa1652c785485519eb96b8984dd4cbb7d67f22aef79d8093

Contents?: true

Size: 1.16 KB

Versions: 10

Compression:

Stored size: 1.16 KB

Contents

class Exercism
  class Assignment

    def self.save(data, path)
      data['assignments'].map do |attributes|
        new(attributes.merge('project_dir' => path)).save
      end
    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 exercise
      File.join(track, slug)
    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

10 entries across 10 versions & 1 rubygems

Version Path
exercism-0.0.28 lib/exercism/assignment.rb
exercism-0.0.27 lib/exercism/assignment.rb
exercism-0.0.26 lib/exercism/assignment.rb
exercism-0.0.25 lib/exercism/assignment.rb
exercism-0.0.24 lib/exercism/assignment.rb
exercism-0.0.23 lib/exercism/assignment.rb
exercism-0.0.22 lib/exercism/assignment.rb
exercism-0.0.21 lib/exercism/assignment.rb
exercism-0.0.20 lib/exercism/assignment.rb
exercism-0.0.19 lib/exercism/assignment.rb