lib/solve/constraint.rb
# Split a constraint string into an Array of two elements. The first
# element being the operator and second being the version string.
#
# If the given string does not contain a constraint operator then (=)
# will be used.
#
# If the given string does not contain a valid version string then
# nil will be returned.
#
# @param [#to_s] constraint
#
# @example splitting a string with a constraint operator and valid version string
#   Constraint.split(">= 1.0.0") => [ ">=", "1.0.0" ]
#
# @example splitting a string without a constraint operator
#   Constraint.split("0.0.0") => [ "=", "1.0.0" ]
#
# @example splitting a string without a valid version string
#   Constraint.split("hello") => nil
#
# @return [Array, nil]
Split a constraint string into an Array of two elements. The first
element being the operator and second being the version string.

If the given string does not contain a constraint operator then (=)
will be used.

If the given string does not contain a valid version string then
nil will be returned.
Split a constraint string into an Array of two elements . The first element being the operator and second being the version string . If the given string does not contain a constraint operator then ( = ) will be used . If the given string does not contain a valid version string then nil will be returned .
def split(constraint)
        if constraint =~ /^[0-9]/
          operator = "="
          version  = constraint
        else
          _, operator, version = REGEXP.match(constraint).to_a
        end
        if operator.nil?
          raise Errors::InvalidConstraintFormat.new(constraint)
        end
        split_version = case version.to_s
                        when /^(\d+)\.(\d+)\.(\d+)(-([0-9a-z\-\.]+))?(\+([0-9a-z\-\.]+))?$/i
                          [ $1.to_i, $2.to_i, $3.to_i, $5, $7 ]
                        when /^(\d+)\.(\d+)\.(\d+)?$/
                          [ $1.to_i, $2.to_i, $3.to_i, nil, nil ]
                        when /^(\d+)\.(\d+)?$/
                          [ $1.to_i, $2.to_i, nil, nil, nil ]
                        when /^(\d+)$/
                          [ $1.to_i, nil, nil, nil, nil ]
                        else
                          raise Errors::InvalidConstraintFormat.new(constraint)
                        end
        [ operator, split_version ].flatten
      end
def split ( constraint ) if constraint =~ / ^[0-9] / operator = "=" version = constraint else _ , operator , version = REGEXP . match ( constraint ) . to_a end if operator . nil? raise Errors :: InvalidConstraintFormat . new ( constraint ) end split_version = case version . to_s when / ^( \d +) \. ( \d +) \. ( \d +)(-([0-9a-z \- \. ]+))?( \+ ([0-9a-z \- \. ]+))?$ /i [ $1 . to_i , $2 . to_i , $3 . to_i , $5 , $7 ] when / ^( \d +) \. ( \d +) \. ( \d +)?$ / [ $1 . to_i , $2 . to_i , $3 . to_i , nil , nil ] when / ^( \d +) \. ( \d +)?$ / [ $1 . to_i , $2 . to_i , nil , nil , nil ] when / ^( \d +)$ / [ $1 . to_i , nil , nil , nil , nil ] else raise Errors :: InvalidConstraintFormat . new ( constraint ) end [ operator , split_version ] . flatten end
Split a constraint string into an Array of two elements.
Split a constraint string into an Array of two elements .
None
Array, nil
constraint
<not_specific>
<not_specific>
None
example
splitting a string with a constraint operator and valid version string Constraint.split(">= 1.0.0") => [ ">=", "1.0.0" ]
splitting a string with a constraint operator and valid version string Constraint . split ( " > = 1 . 0 . 0 " ) = > [ " > = " " 1 . 0 . 0 " ]
example
None
example
splitting a string without a valid version string Constraint.split("hello") => nil
splitting a string without a valid version string Constraint . split ( " hello " ) = > nil