File: api.rb

package info (click to toggle)
ruby-version-gem 1.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 144 kB
  • sloc: ruby: 105; makefile: 4
file content (66 lines) | stat: -rw-r--r-- 1,121 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
module VersionGem
  module Api
    # The version number as a string
    #
    # @return [String]
    def to_s
      self::VERSION
    end

    # The major version
    #
    # @return [Integer]
    def major
      @major ||= _to_a[0].to_i
    end

    # The minor version
    #
    # @return [Integer]
    def minor
      @minor ||= _to_a[1].to_i
    end

    # The patch version
    #
    # @return [Integer]
    def patch
      @patch ||= _to_a[2].to_i
    end

    # The pre-release version, if any
    #
    # @return [String, NilClass]
    def pre
      @pre ||= _to_a[3]
    end

    # The version number as a hash
    #
    # @return [Hash]
    def to_h
      @to_h ||= {
        major: major,
        minor: minor,
        patch: patch,
        pre: pre
      }
    end

    # The version number as an array of cast values
    #
    # @return [Array<[Integer, String, NilClass]>]
    def to_a
      @to_a ||= [major, minor, patch, pre]
    end

    private

    # The version number as an array of strings
    #
    # @return [Array<String>]
    def _to_a
      @_to_a = self::VERSION.split('.')
    end
  end
end