semver_check 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -3
- data/lib/semver_check/version.rb +1 -1
- data/lib/semver_check.rb +11 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdc39dd369f29e6ebe018a881038e1a0f0255be4238717016588ebfc68a92e5e
|
4
|
+
data.tar.gz: 549fc59387e661c8e2c0b7c7454fd12ca3f6993f142884b5773a14addbf4f832
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14e21f9954a5555fe8e233029e30008ca5f489db65c2cd0ff7c59dcd89c0a2e8c8d5a19c09a8f94cd26110f2338c5ceebafcc27bd05749aa5ff56bfe4fa90ce5
|
7
|
+
data.tar.gz: 17db55a207756a196f7a6b8a2f0ebabffb6c3d7c8415366909a8a8afe2cdd1e5a95cb9617a43a723ee57e8373f4d06c46741a3fbb585e44b6958fc8d56557e1b
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# SemverCheck
|
2
2
|
|
3
|
-
|
3
|
+
A simple gem containing one class `SemverCheck::Compare` to compare SemVer strings.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -14,7 +14,19 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
14
14
|
|
15
15
|
## Usage
|
16
16
|
|
17
|
-
|
17
|
+
The Compare class includes the Comparable module, so all methods from there and in addition != are available.
|
18
|
+
|
19
|
+
````ruby
|
20
|
+
SemverCheck::Compare.new("1.2.3") < SemverCheck::Compare.new("1.2.4") # true
|
21
|
+
SemverCheck::Compare.new("1.2.3") > SemverCheck::Compare.new("1.2.2") # true
|
22
|
+
SemverCheck::Compare.new("1.2.3") <= SemverCheck::Compare.new("1.2.3") # true
|
23
|
+
SemverCheck::Compare.new("1.2.3") >= SemverCheck::Compare.new("1.2.3") # true
|
24
|
+
# works also with prerelease
|
25
|
+
SemverCheck::Compare.new("1.2.3-alpha") < SemverCheck::Compare.new("1.2.3-beta") # true
|
26
|
+
SemverCheck::Compare.new("1.2.3-alpha.2") > SemverCheck::Compare.new("1.2.3-alpha.1") # true
|
27
|
+
````
|
28
|
+
|
29
|
+
You get the idea. If you wanna know more check out the `test/test_compare.rb` file.
|
18
30
|
|
19
31
|
## Development
|
20
32
|
|
@@ -24,7 +36,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
24
36
|
|
25
37
|
## Contributing
|
26
38
|
|
27
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/the-pulli/semver_check.
|
28
40
|
|
29
41
|
## License
|
30
42
|
|
data/lib/semver_check/version.rb
CHANGED
data/lib/semver_check.rb
CHANGED
@@ -23,16 +23,16 @@ module SemverCheck
|
|
23
23
|
\Z/x
|
24
24
|
|
25
25
|
MAPPING_TABLE = [
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
["n", 1],
|
27
|
+
["sn", 1],
|
28
|
+
["ssn", 1],
|
29
|
+
["o", -1],
|
30
|
+
["so", -1],
|
31
|
+
["sso", -1],
|
32
|
+
["sss", 0]
|
33
33
|
].freeze
|
34
34
|
|
35
|
-
|
35
|
+
VERSION_PARTS = %i[major minor patch].freeze
|
36
36
|
|
37
37
|
attr_reader :version
|
38
38
|
|
@@ -57,7 +57,7 @@ module SemverCheck
|
|
57
57
|
private
|
58
58
|
|
59
59
|
def comparison(other)
|
60
|
-
comparison =
|
60
|
+
comparison = VERSION_PARTS.map do |part|
|
61
61
|
if @version[part] == other.version[part]
|
62
62
|
"s"
|
63
63
|
elsif @version[part] > other.version[part]
|
@@ -106,7 +106,7 @@ module SemverCheck
|
|
106
106
|
def match(comparison)
|
107
107
|
MAPPING_TABLE.find do |m|
|
108
108
|
comparison.start_with?(m.first)
|
109
|
-
end.last
|
109
|
+
end.last
|
110
110
|
end
|
111
111
|
|
112
112
|
def prepare_version(version)
|
@@ -115,7 +115,7 @@ module SemverCheck
|
|
115
115
|
|
116
116
|
version = version.named_captures.transform_keys(&:to_sym)
|
117
117
|
# convert major, minor and patch to int
|
118
|
-
|
118
|
+
VERSION_PARTS.each { |part| version[part] = version[part].to_i }
|
119
119
|
version
|
120
120
|
end
|
121
121
|
end
|