Module: ElmInstall::Utils

Includes:
Contracts::Builtin, Contracts::Core
Defined in:
lib/elm_install/utils.rb

Overview

This module contains utility functions.

Constant Summary collapse

CONVERTERS =

Regexes for converting constraints.

{
  /v<(?!=)(.*)/ => '<',
  /(.*)<=v/ => '>=',
  /v<=(.*)/ => '<=',
  /(.*)<v/ => '>'
}.freeze

Class Method Summary collapse

Class Method Details

.transform_constraint(elm_constraint) ⇒ Array

Transform an ‘elm’ constraint into a proper one.

Parameters:

  • elm_constraint (String)

    The elm constraint

Returns:

  • (Array)

    The transform constraints



23
24
25
26
27
28
29
30
31
# File 'lib/elm_install/utils.rb', line 23

def transform_constraint(elm_constraint)
  elm_constraint.gsub!(/\s/, '')

  CONVERTERS
    .map { |regexp, prefix| [elm_constraint.match(regexp), prefix] }
    .select { |(match)| match }
    .map { |(match, prefix)| "#{prefix} #{match[1]}" }
    .map { |constraint| Solve::Constraint.new constraint }
end