Sha256: 1b725c63c525517eb4ab0a71646a23986e54cf2ae52f1de04be3ba47e8963ffc

Contents?: true

Size: 885 Bytes

Versions: 2

Compression:

Stored size: 885 Bytes

Contents

class Exercism
  class Assignment

    attr_reader :track, :slug, :readme, :testfile, :tests

    def initialize(attributes)
      @track = attributes['track']
      @slug = attributes['slug']
      @readme = attributes['readme']
      @testfile = attributes['testfile']
      @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, testfile)
    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

2 entries across 2 versions & 1 rubygems

Version Path
exercism-0.0.3 lib/exercism/assignment.rb
exercism-0.0.2 lib/exercism/assignment.rb