simple-version 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/simple_version.rb +58 -0
- metadata +80 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
class SimpleVersion
|
2
|
+
|
3
|
+
attr_reader :major, :minor, :micro
|
4
|
+
|
5
|
+
def initialize(major, minor, micro)
|
6
|
+
@major = to_integer(major)
|
7
|
+
@minor = to_integer(minor)
|
8
|
+
@micro = to_integer(micro)
|
9
|
+
end
|
10
|
+
|
11
|
+
def SimpleVersion.parse(version_string)
|
12
|
+
if version_string.to_s.strip == ""
|
13
|
+
raise "version_string cannot be blank"
|
14
|
+
end
|
15
|
+
pieces = version_string.split(".", 3)
|
16
|
+
if pieces.size != 3
|
17
|
+
raise "version must have 3 pieces"
|
18
|
+
end
|
19
|
+
SimpleVersion.new(pieces[0], pieces[1], pieces[2])
|
20
|
+
end
|
21
|
+
|
22
|
+
def next_major
|
23
|
+
SimpleVersion.new(major+1, 0, 0)
|
24
|
+
end
|
25
|
+
|
26
|
+
def next_minor
|
27
|
+
SimpleVersion.new(major, minor+1, 0)
|
28
|
+
end
|
29
|
+
|
30
|
+
def next_micro
|
31
|
+
SimpleVersion.new(major, minor, micro+1)
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_s
|
35
|
+
"%s.%s.%s" % [major, minor, micro]
|
36
|
+
end
|
37
|
+
|
38
|
+
def <=>(other)
|
39
|
+
value = major <=> other.major
|
40
|
+
if value == 0
|
41
|
+
value = minor <=> other.minor
|
42
|
+
if value == 0
|
43
|
+
value = micro <=> other.micro
|
44
|
+
end
|
45
|
+
end
|
46
|
+
value
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
def to_integer(value)
|
51
|
+
if value.to_s.match(/^\d+$/)
|
52
|
+
value.to_i
|
53
|
+
else
|
54
|
+
raise "Value[%s] is not an integer" % value
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple-version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Michael Bryzek
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2013-10-18 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Simple, well-tested library to parse or create version strings
|
36
|
+
email: mbryzek@alum.mit.edu
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- lib/simple_version.rb
|
45
|
+
has_rdoc: true
|
46
|
+
homepage: http://rubygems.org/gems/simple-version
|
47
|
+
licenses:
|
48
|
+
- Apache License, Version 2.0
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.4.2
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: A simple API to manage version strings ala 1.2.3
|
79
|
+
test_files: []
|
80
|
+
|