Sha256: cebe9fb58257afbf9f114a1e197b75828c90a8a9c9c18b72537959d541ea9602

Contents?: true

Size: 916 Bytes

Versions: 189

Compression:

Stored size: 916 Bytes

Contents

require "ecr"
require "json"

abstract class ExerciseGenerator
  METADATA_REPOSITORY = "x-common"

  def self.generate
    new.generate
  end

  def generate
    raise "There are no test cases for #{exercise_name}" if test_cases.empty?
    File.write(test_file, to_s)
  end

  def describe_name
    exercise_name.split('-').map(&.capitalize).join
  end

  abstract def exercise_name
  abstract def test_cases

  private def root
    File.expand_path(File.join("..", "..", "..", ".."), __FILE__)
  end

  private def test_file
    File.expand_path(File.join("exercises", exercise_name, "spec", "#{exercise_name.tr("-", "_")}_spec.cr"), root)
  end

  private def metadata_dir
    File.expand_path(File.join("..", METADATA_REPOSITORY, "exercises", exercise_name), root)
  end

  private def data
    File.read(File.join(metadata_dir, "canonical-data.json"))
  end

  ECR.def_to_s "#{__DIR__}/templates/example.tt"
end

Version data entries

189 entries across 189 versions & 1 rubygems

Version Path
trackler-2.0.8.28 tracks/crystal/src/generator/exercises/exercise_generator.cr
trackler-2.0.8.27 tracks/crystal/src/generator/exercises/exercise_generator.cr
trackler-2.0.8.26 tracks/crystal/src/generator/exercises/exercise_generator.cr
trackler-2.0.8.24 tracks/crystal/src/generator/exercises/exercise_generator.cr
trackler-2.0.8.23 tracks/crystal/src/generator/exercises/exercise_generator.cr
trackler-2.0.8.22 tracks/crystal/src/generator/exercises/exercise_generator.cr
trackler-2.0.8.21 tracks/crystal/src/generator/exercises/exercise_generator.cr
trackler-2.0.8.20 tracks/crystal/src/generator/exercises/exercise_generator.cr
trackler-2.0.8.19 tracks/crystal/src/generator/exercises/exercise_generator.cr
trackler-2.0.8.18 tracks/crystal/src/generator/exercises/exercise_generator.cr
trackler-2.0.8.17 tracks/crystal/src/generator/exercises/exercise_generator.cr
trackler-2.0.8.16 tracks/crystal/src/generator/exercises/exercise_generator.cr
trackler-2.0.8.15 tracks/crystal/src/generator/exercises/exercise_generator.cr
trackler-2.0.8.14 tracks/crystal/src/generator/exercises/exercise_generator.cr
trackler-2.0.8.13 tracks/crystal/src/generator/exercises/exercise_generator.cr
trackler-2.0.8.12 tracks/crystal/src/generator/exercises/exercise_generator.cr
trackler-2.0.8.11 tracks/crystal/src/generator/exercises/exercise_generator.cr
trackler-2.0.8.10 tracks/crystal/src/generator/exercises/exercise_generator.cr
trackler-2.0.8.9 tracks/crystal/src/generator/exercises/exercise_generator.cr
trackler-2.0.8.8 tracks/crystal/src/generator/exercises/exercise_generator.cr