Sha256: 56683fd3653bb03c6aae8408182337c552809068374bb2e6c9134cc0657d4f8b

Contents?: true

Size: 762 Bytes

Versions: 4

Compression:

Stored size: 762 Bytes

Contents

# frozen_string_literal: true
class Coursemology::Polyglot::Language
  # Finds the language class with the specified name.
  #
  # @param [String] type The name of the class.
  # @return [nil] If the type is not defined.
  # @return [Class] If the type was found.
  def self.find_by(type:)
    class_ = concrete_languages.find { |language| language.name == type }
    class_.new if class_
  end

  # Finds the language class with the specified name.
  #
  # @param [String] type The name of the class.
  # @return [Class] If the type was found.
  # @raise [ArgumentError] When the type was not found.
  def self.find_by!(type:)
    language = find_by(type: type)
    fail ArgumentError, "Cannot find the language #{type}" unless language

    language
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
coursemology-evaluator-0.1.9 lib/coursemology/polyglot/extensions/language.rb
coursemology-evaluator-0.1.8 lib/coursemology/polyglot/extensions/language.rb
coursemology-evaluator-0.1.7 lib/coursemology/polyglot/extensions/language.rb
coursemology-evaluator-0.1.1 lib/coursemology/polyglot/extensions/language.rb