Sha256: f7e6444a607f9d2f9f0086af9f873d11f7f73e050a4f33d520519ac0cc09de80

Contents?: true

Size: 1.35 KB

Versions: 29

Compression:

Stored size: 1.35 KB

Contents

#!/usr/bin/env ruby

# This is a temporary file which exists to support the x-common issue #767
# [Make description.md self contained.](# https://github.com/exercism/x-common/issues/767)
#
# The exercise description given in description.md should be complete and self
# contained, and not require the addition of the blurb to make sense.
#
# This script copies the current blurb into description.md for all exercises.
#
# It will NOT update the description if it already begins with the blurb.
# Thus this script will not add multiple blurbs if it is run multiple times.

require 'yaml'

class Exercise
  attr_reader :path
  def initialize(path)
    @path = path
  end

  def update_description
    unless description.start_with?(blurb)
      complete_description = format("%s\n\n%s", blurb, description)
      File.write(description_filename, complete_description)
    end
  end

  private

  def blurb
    metadata['blurb']
  end

  def metadata
    metadata_filename = File.join(path, 'metadata.yml')
    YAML.load_file(metadata_filename)
  end

  def description
    File.read(description_filename)
  end

  def description_filename
    File.join(path, 'description.md')
  end
end


exercises = Dir.glob('exercises/*').map {|path| Exercise.new(path)}

updated = exercises.count do |exercise|
  exercise.update_description
end

puts "#{updated}/#{exercises.count} exercises updated"

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
trackler-2.1.0.48 common/bin/transfer_blurb_to_description.rb
trackler-2.1.0.47 common/bin/transfer_blurb_to_description.rb
trackler-2.1.0.46 common/bin/transfer_blurb_to_description.rb
trackler-2.1.0.45 common/bin/transfer_blurb_to_description.rb
trackler-2.1.0.44 common/bin/transfer_blurb_to_description.rb
trackler-2.1.0.43 common/bin/transfer_blurb_to_description.rb
trackler-2.1.0.42 common/bin/transfer_blurb_to_description.rb
trackler-2.1.0.41 common/bin/transfer_blurb_to_description.rb
trackler-2.1.0.40 common/bin/transfer_blurb_to_description.rb
trackler-2.1.0.39 common/bin/transfer_blurb_to_description.rb
trackler-2.1.0.38 common/bin/transfer_blurb_to_description.rb
trackler-2.1.0.37 common/bin/transfer_blurb_to_description.rb
trackler-2.1.0.36 common/bin/transfer_blurb_to_description.rb
trackler-2.1.0.34 common/bin/transfer_blurb_to_description.rb
trackler-2.1.0.33 common/bin/transfer_blurb_to_description.rb
trackler-2.1.0.32 common/bin/transfer_blurb_to_description.rb
trackler-2.1.0.31 common/bin/transfer_blurb_to_description.rb
trackler-2.1.0.30 common/bin/transfer_blurb_to_description.rb
trackler-2.1.0.29 common/bin/transfer_blurb_to_description.rb
trackler-2.1.0.28 common/bin/transfer_blurb_to_description.rb