Sha256: 8f1e0f6e2c62325b5c64ef85b8ebfcc0f02defdc77ac6f5c656c68f1afdff29c

Contents?: true

Size: 923 Bytes

Versions: 1

Compression:

Stored size: 923 Bytes

Contents

module Doc
  class Configurator
    class Ruby
      class VersionSpecifier
        attr_reader :str, :parts
        alias_method :to_s, :str
        def initialize(o)
          @str = o.to_s
          @parts = str.scan(/\d+/).map(&:to_i)
        end

        def drop
          self.class.new(parts.drop(1).join('.'))
        end

        def valid?
          str =~ /^\d+\.\d+(?:\.\d+(?:-p\d+)?)?$/
        end

        def full_version?
          valid? && parts.length == 4
        end

        def dir_name
          fmt = 'ruby' + %w[-%d .%d .%d -p%d].take(parts.length).join('')
          fmt % parts
        end

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

        def ===(other)
          if other.respond_to?(:parts)
            parts == other.parts[0, parts.length]
          else
            str === other
          end
        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/version_specifier.rb