Sha256: efbd4ccd49086fe644b79f9bc04456d2ef249b606881471c95d3d2e5a38eef84

Contents?: true

Size: 1.12 KB

Versions: 6

Compression:

Stored size: 1.12 KB

Contents

class Exercism
  class Assignment

    def self.save(data, path)
      data['assignments'].map do |attributes|
        Assignment.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 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

6 entries across 6 versions & 1 rubygems

Version Path
exercism-0.0.18 lib/exercism/assignment.rb
exercism-0.0.17 lib/exercism/assignment.rb
exercism-0.0.16 lib/exercism/assignment.rb
exercism-0.0.15 lib/exercism/assignment.rb
exercism-0.0.14 lib/exercism/assignment.rb
exercism-0.0.13 lib/exercism/assignment.rb