Class: Jsapi::Meta::OpenAPI::Version
- Inherits:
-
Object
- Object
- Jsapi::Meta::OpenAPI::Version
- Includes:
- Comparable
- Defined in:
- lib/jsapi/meta/openapi/version.rb
Instance Attribute Summary collapse
-
#major ⇒ Object
readonly
Returns the value of attribute major.
-
#minor ⇒ Object
readonly
Returns the value of attribute minor.
Class Method Summary collapse
-
.from(version) ⇒ Object
Transforms
versionto an instance of this class.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#==(other) ⇒ Object
:nodoc:.
-
#initialize(major, minor) ⇒ Version
constructor
A new instance of Version.
-
#inspect ⇒ Object
:nodoc:.
-
#to_s ⇒ Object
(also: #as_json)
:nodoc:.
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
#major ⇒ Object (readonly)
Returns the value of attribute major.
29 30 31 |
# File 'lib/jsapi/meta/openapi/version.rb', line 29 def major @major end |
#minor ⇒ Object (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 |
#inspect ⇒ Object
:nodoc:
51 52 53 |
# File 'lib/jsapi/meta/openapi/version.rb', line 51 def inspect # :nodoc: "<#{self.class.name} #{self}>" end |
#to_s ⇒ Object 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 |