Sha256: 48de1ea4c9cc1bb91bf6c3cdc373acfd427889f1766302fbb90b932ca850709d

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

module Doc
  class Configurator
    class Ruby
      class PathInfo < Struct.new(:path, :name, :type, :full_version, :parts)
        private_class_method :new
        def self.latest_matching(version, paths)
          paths.map(&method(:for_path)).compact.grep(version).sort.last
        end

        def self.for_path(path)
          name = path.basename.to_s
          if name =~ /^ruby-(\d+\.\d+\.\d+(?:-p\d+)?)(?i:\.(tar\.(?:gz|bz2)|tgz|tbz|zip))?$/
            extension = $2 ? $2.downcase : :dir
            type = ({'tar.bz2' => 'tbz', 'tar.gz' => 'tgz'}[extension] || extension).to_sym
            new(path, name, type, $1, $1.scan(/\d+/).map(&:to_i))
          end
        end

        def type_priority
          @type_priority ||= {:zip => 0, :tgz => 1, :tbz => 2, :dir => 3}[type]
        end

        def sort_by
          @sort_by ||= [parts, type_priority]
        end

        include Comparable
        def <=>(other)
          sort_by <=> other.sort_by
        end

        def ===(other)
          parts === other.parts
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
doc-0.5.0 lib/doc/configurator/ruby/path_info.rb