Class: Semver::String
- Inherits:
-
Object
- Object
- Semver::String
- Defined in:
- lib/semver/string.rb
Overview
A helper class for working with semantic versioning strings.
~~~ version = Semver::String.new(‘1.2.3-alpha+build-123’)
version.major #=> 1 version.major #=> 2 version.patch #=> 3 version.pre_release #=> alpha version.build_metadata #=> build-123 version.to_s #=> “1.2.3-alpha+build-123” ~~~
Instance Attribute Summary collapse
- #build_metadata ⇒ String? readonly
- #major ⇒ Integer readonly
- #minor ⇒ Integer readonly
- #patch ⇒ Integer readonly
- #pre_release ⇒ String? readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
See section #11 of semver.org/spec/v2.0.0.html.
-
#==(other) ⇒ Boolean
Returns ‘true` if the string value of the two objects are equal.
- #eql?(other) ⇒ Boolean private
-
#initialize(major:, minor:, patch:, pre_release: nil, build_metadata: nil) ⇒ String
constructor
A new instance of String.
- #to_str ⇒ String (also: #to_s)
Constructor Details
#initialize(major:, minor:, patch:, pre_release: nil, build_metadata: nil) ⇒ String
Returns a new instance of String.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/semver/string.rb', line 36 def initialize( major:, minor:, patch:, pre_release: nil, build_metadata: nil ) @major = major @minor = minor @patch = patch @pre_release = pre_release @build_metadata = @string = format_string end |
Instance Attribute Details
#build_metadata ⇒ String? (readonly)
64 65 66 |
# File 'lib/semver/string.rb', line 64 def @build_metadata end |
#major ⇒ Integer (readonly)
52 53 54 |
# File 'lib/semver/string.rb', line 52 def major @major end |
#minor ⇒ Integer (readonly)
55 56 57 |
# File 'lib/semver/string.rb', line 55 def minor @minor end |
#patch ⇒ Integer (readonly)
58 59 60 |
# File 'lib/semver/string.rb', line 58 def patch @patch end |
#pre_release ⇒ String? (readonly)
61 62 63 |
# File 'lib/semver/string.rb', line 61 def pre_release @pre_release end |
Class Method Details
Instance Method Details
#<=>(other) ⇒ Integer
See section #11 of semver.org/spec/v2.0.0.html
90 91 92 |
# File 'lib/semver/string.rb', line 90 def <=>(other) Comparator.new.compare(left: self, right: other) end |
#==(other) ⇒ Boolean
Returns ‘true` if the string value of the two objects are equal.
84 85 86 |
# File 'lib/semver/string.rb', line 84 def ==(other) to_s == other.to_s end |
#eql?(other) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
74 75 76 77 78 79 80 |
# File 'lib/semver/string.rb', line 74 def eql?(other) if other.is_a?(Semver::String) to_str == other.to_str else false end end |
#to_str ⇒ String Also known as: to_s
67 68 69 |
# File 'lib/semver/string.rb', line 67 def to_str @string end |