Sha256: 9a3d151fa04b335b620f3dc06fb03cf828b057d22ccdb4ede9d0021f1ffd9e36

Contents?: true

Size: 1.11 KB

Versions: 4

Compression:

Stored size: 1.11 KB

Contents

module JBundler
  module MavenVersion
    
    def to_version(*args)
      if args.size == 0
        "[0,)"
      else
        low, high = convert(args[0])
        low, high = convert(args[1], low, high) if args[1] =~ /[=~><]/
        if low == high
          low
        else
          "#{low || '[0'},#{high || ')'}"
        end
      end
    end
    
    private

    def convert(arg, low = nil, high = nil)
      if arg =~ /~>/
        val = arg.sub(/~>\s*/, '')
        last = val.sub(/\.[^.]+$/, '.99999')
        ["[#{val}", "#{last}]"]
      elsif arg =~ />=/
        val = arg.sub(/>=\s*/, '')
        ["[#{val}", (nil || high)]
      elsif arg =~ /<=/
        val = arg.sub(/<=\s*/, '')
        [(nil || low), "#{val}]"]
        # treat '!' the same way as '>' since maven can not describe such range
      elsif arg =~ /[!>]/  
        val = arg.sub(/>\s*/, '')
        ["(#{val}", (nil || high)]
      elsif arg =~ /</
        val = arg.sub(/<\s*/, '')
        [(nil || low), "#{val})"]
      elsif arg =~ /\=/
        val = arg.sub(/=\s*/, '')
        [val, val]
      else
        [arg, arg]
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jbundler-0.3.0 lib/jbundler/maven_util.rb~
jbundler-0.2.2 lib/jbundler/maven_util.rb~
jbundler-0.2.1 lib/jbundler/maven_util.rb~
jbundler-0.2.0 lib/jbundler/maven_util.rb~