File: version.rb

package info (click to toggle)
ruby-shoulda-matchers 7.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,652 kB
  • sloc: ruby: 34,046; sh: 280; makefile: 9
file content (45 lines) | stat: -rw-r--r-- 797 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module Tests
  class Version
    def initialize(version)
      @version = Gem::Version.new(version.to_s)
    end

    def <(other_version)
      compare?(:<, other_version)
    end

    def <=(other_version)
      compare?(:<=, other_version)
    end

    def ==(other_version)
      compare?(:==, other_version)
    end

    def >=(other_version)
      compare?(:>=, other_version)
    end

    def >(other_version)
      compare?(:>, other_version)
    end

    def =~(other_version)
      Gem::Requirement.new(other_version).satisfied_by?(version)
    end

    def to_s
      version.to_s
    end

    protected

    attr_reader :version

    private

    def compare?(operator, other_version)
      Gem::Requirement.new("#{operator} #{other_version}").satisfied_by?(version)
    end
  end
end