Sha256: e4f3c847685cdc8b24332d993ff70b286dc2b3ca28ddae5f268c43f7af8b2a4f

Contents?: true

Size: 1019 Bytes

Versions: 1

Compression:

Stored size: 1019 Bytes

Contents

class Exercism
  class Assignment

    def self.save(data)
      data['assignments'].each do |attributes|
        Assignment.new(attributes).save
      end
    end

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

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

    def save
      FileUtils.mkdir_p assignment_dir
      File.open readme_path, 'w' do |f|
        f.write readme
      end
      File.write tests_path, tests
    end

    private

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

    def tests_path
      File.join(assignment_dir, test_file)
    end

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

    def project_dir
      dir = FileUtils.pwd
      if File.basename(dir) == track
        dir.gsub(/#{track}\z/, '')
      else
        dir
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
exercism-0.0.4 lib/exercism/assignment.rb