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

Inherits:
Object
  • Object
show all
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.



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

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

Instance Attribute Details

#majorObject (readonly)

Returns the value of attribute major.



25
26
27
# File 'lib/jsapi/meta/openapi/version.rb', line 25

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



25
26
27
# File 'lib/jsapi/meta/openapi/version.rb', line 25

def minor
  @minor
end

Class Method Details

.from(version) ⇒ Object

Creates an OpenAPI version from version.

Raises an ArgumentError if version isn`t supported.



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

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)
  else
    raise ArgumentError, "unsupported OpenAPI version: #{version.inspect}"
  end
end

Instance Method Details

#==(other) ⇒ Object

:nodoc:



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

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

#to_sObject

:nodoc:



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

def to_s # :nodoc:
  "#{major}.#{minor}"
end