Class: Jsapi::Meta::OpenAPI::Version

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/jsapi/meta/openapi/version.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(major, minor) ⇒ Version

Returns a new instance of Version.



31
32
33
34
# File 'lib/jsapi/meta/openapi/version.rb', line 31

def initialize(major, minor)
  @major = major
  @minor = minor
end

Instance Attribute Details

#majorObject (readonly)

Returns the value of attribute major.



29
30
31
# File 'lib/jsapi/meta/openapi/version.rb', line 29

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



29
30
31
# File 'lib/jsapi/meta/openapi/version.rb', line 29

def minor
  @minor
end

Class Method Details

.from(version) ⇒ Object

Transforms version to an instance of this class.

Raises an ArgumentError if version could not be transformed.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/jsapi/meta/openapi/version.rb', line 12

def self.from(version)
  return version if version.is_a?(Version)

  case version
  when '2.0', 2, nil
    new(2, 0)
  when '3.0', 3
    new(3, 0)
  when '3.1'
    new(3, 1)
  when '3.2'
    new(3, 2)
  else
    raise ArgumentError, "unsupported OpenAPI version: #{version.inspect}"
  end
end

Instance Method Details

#<=>(other) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/jsapi/meta/openapi/version.rb', line 42

def <=>(other)
  return unless other.is_a?(Version)

  result = major <=> other.major
  return result unless result.zero?

  minor <=> other.minor
end

#==(other) ⇒ Object

:nodoc:



36
37
38
39
40
# File 'lib/jsapi/meta/openapi/version.rb', line 36

def ==(other) # :nodoc:
  other.is_a?(self.class) &&
    @major == other.major &&
    @minor == other.minor
end

#inspectObject

:nodoc:



51
52
53
# File 'lib/jsapi/meta/openapi/version.rb', line 51

def inspect # :nodoc:
  "<#{self.class.name} #{self}>"
end

#to_sObject Also known as: as_json

:nodoc:



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/jsapi/meta/openapi/version.rb', line 55

def to_s # :nodoc:
  @to_s ||=
    case [major, minor]
    when [3, 0]
      '3.0.3'
    when [3, 1]
      '3.1.1'
    when [3, 2]
      '3.2.0'
    else
      "#{major}.#{minor}"
    end
end