Sha256: bc026f4dfeec648a5aa02129456a2c1633bb956dc927e7e16df8cafa8cb30e8d

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

# This module is extended by the language's singleton class when the Language can be directly used
# by the user.
#
# This is deliberately defined so that consumers of this library can inject methods into all
# concrete languages' classes.
module Coursemology::Polyglot::ConcreteLanguage::ClassMethods
  # The default algorithm for translating a language to a corresponding Docker image name.
  #
  # This will:
  #  1. Strip the +Coursemology::Polyglot::Language+ prefix.
  #  2. Underscore the name.
  #  3. Replace *n*Point*n* strings with dots (e.g. Python2Point7 to Python2.7).
  #  4. Replace slashes with dashes.
  def docker_image
    # Remove the Coursemology::Polyglot::Language prefix
    class_name = name
    class_name = class_name.sub(/^Coursemology::Polyglot::Language::/, '')

    # Use the underscored name
    class_name = class_name.underscore

    # Replace the "_point" string with a decimal
    class_name.gsub!(/(?<=[\d])_point(?=[\d])/, '.')

    # Replace slashes with dashes
    class_name.tr!('/', '-')
    class_name
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
coursemology-polyglot-0.0.3 lib/coursemology/polyglot/concrete_language/class_methods.rb