ruby-version 0.1.0
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/.document +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +22 -0
- data/LICENSE.txt +20 -0
- data/README.md +29 -0
- data/Rakefile +29 -0
- data/VERSION +1 -0
- data/lib/ruby-version.rb +135 -0
- data/test +41 -0
- metadata +109 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
gem "hash-utils", ">= 0.16.0"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "bundler", ">= 1.0.0"
|
10
|
+
gem "jeweler", ">= 1.5.2"
|
11
|
+
gem "riot", ">= 0.12.3"
|
12
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
git (1.2.5)
|
5
|
+
hash-utils (0.16.0)
|
6
|
+
jeweler (1.6.2)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rake (0.9.2)
|
11
|
+
riot (0.12.4)
|
12
|
+
rr
|
13
|
+
rr (1.0.2)
|
14
|
+
|
15
|
+
PLATFORMS
|
16
|
+
ruby
|
17
|
+
|
18
|
+
DEPENDENCIES
|
19
|
+
bundler (>= 1.0.0)
|
20
|
+
hash-utils (>= 0.16.0)
|
21
|
+
jeweler (>= 1.5.2)
|
22
|
+
riot (>= 0.12.3)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Martin Kozák
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
Ruby Version
|
2
|
+
============
|
3
|
+
|
4
|
+
**ruby-version** serves as wrapper module for the `RUBY_VERSION` constant
|
5
|
+
with matching the version numbers. Usage is simple:
|
6
|
+
|
7
|
+
require "ruby-version"
|
8
|
+
|
9
|
+
Ruby::Version > 1.8.7
|
10
|
+
# will return true for 1.9.2 and false for 1.8.3
|
11
|
+
|
12
|
+
Contributing
|
13
|
+
------------
|
14
|
+
|
15
|
+
1. Fork it.
|
16
|
+
2. Create a branch (`git checkout -b 20101220-my-change`).
|
17
|
+
3. Commit your changes (`git commit -am "Added something"`).
|
18
|
+
4. Push to the branch (`git push origin 20101220-my-change`).
|
19
|
+
5. Create an [Issue][9] with a link to your branch.
|
20
|
+
6. Enjoy a refreshing Diet Coke and wait.
|
21
|
+
|
22
|
+
Copyright
|
23
|
+
---------
|
24
|
+
|
25
|
+
Copyright © 2011 [Martin Kozák][10]. See `LICENSE.txt` for
|
26
|
+
further details.
|
27
|
+
|
28
|
+
[9]: http://github.com/martinkozak/ruby-version/issues
|
29
|
+
[10]: http://www.martinkozak.net/
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'rake'
|
14
|
+
require 'jeweler'
|
15
|
+
|
16
|
+
Jeweler::Tasks.new do |gem|
|
17
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
18
|
+
gem.name = "ruby-version"
|
19
|
+
gem.homepage = "http://github.com/martinkozak/ruby-version"
|
20
|
+
gem.license = "MIT"
|
21
|
+
gem.summary = 'Serves as wrapper module for the RUBY_VERSION constant with matching the version numbers.'
|
22
|
+
gem.email = "martinkozak@martinkozak.net"
|
23
|
+
gem.authors = ["Martin Kozák"]
|
24
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
25
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
26
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
27
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
28
|
+
end
|
29
|
+
Jeweler::RubygemsDotOrgTasks.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/ruby-version.rb
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
3
|
+
|
4
|
+
require "hash-utils/numeric"
|
5
|
+
|
6
|
+
##
|
7
|
+
# Outer wrapper for the {Ruby::Version} module.
|
8
|
+
#
|
9
|
+
|
10
|
+
module Ruby
|
11
|
+
|
12
|
+
##
|
13
|
+
# Wraps the +RUBY_VERSION+ constant and provides some handling
|
14
|
+
# such as comparing.
|
15
|
+
#
|
16
|
+
|
17
|
+
module Version
|
18
|
+
|
19
|
+
##
|
20
|
+
# Contains the Ruby version identification in frozen string.
|
21
|
+
# It's content is equal to the +RUBY_VERSION+ constant.
|
22
|
+
#
|
23
|
+
|
24
|
+
VERSION = RUBY_VERSION.freeze
|
25
|
+
|
26
|
+
##
|
27
|
+
# Higher or equal operator.
|
28
|
+
#
|
29
|
+
# @param [String, Symbol, Array] value version identifier
|
30
|
+
# @return [Boolean] +true+ if yes, +false otherwise
|
31
|
+
#
|
32
|
+
|
33
|
+
def self.>=(value)
|
34
|
+
__compare(value, false, true, true)
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# Lower or equal operator.
|
39
|
+
#
|
40
|
+
# @param [String, Symbol, Array] value version identifier
|
41
|
+
# @return [Boolean] +true+ if yes, +false otherwise
|
42
|
+
#
|
43
|
+
|
44
|
+
def self.<=(value)
|
45
|
+
__compare(value, true, false, true)
|
46
|
+
end
|
47
|
+
|
48
|
+
##
|
49
|
+
# Lower operator.
|
50
|
+
#
|
51
|
+
# @param [String, Symbol, Array] value version identifier
|
52
|
+
# @return [Boolean] +true+ if yes, +false otherwise
|
53
|
+
#
|
54
|
+
|
55
|
+
def self.<(value)
|
56
|
+
__compare(value, true, false, false)
|
57
|
+
end
|
58
|
+
|
59
|
+
##
|
60
|
+
# Higher operator.
|
61
|
+
#
|
62
|
+
# @param [String, Symbol, Array] value version identifier
|
63
|
+
# @return [Boolean] +true+ if yes, +false otherwise
|
64
|
+
#
|
65
|
+
|
66
|
+
def self.>(value)
|
67
|
+
__compare(value, false, true, false)
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Equality operator.
|
72
|
+
#
|
73
|
+
# @param [String, Symbol, Array] value version identifier
|
74
|
+
# @return [Boolean] +true+ if yes, +false otherwise
|
75
|
+
#
|
76
|
+
|
77
|
+
def self.==(value)
|
78
|
+
__compare(value, false, false, true)
|
79
|
+
end
|
80
|
+
|
81
|
+
##
|
82
|
+
# Compares version strings.
|
83
|
+
#
|
84
|
+
# @param [String, Symbol, Array] value version identifier
|
85
|
+
# @return [Boolean] +1+ if this one is higher, +-1+ if lower and +0+ otherwise
|
86
|
+
#
|
87
|
+
|
88
|
+
def self.compare(value)
|
89
|
+
__compare(value, -1, 1, 0)
|
90
|
+
end
|
91
|
+
|
92
|
+
##
|
93
|
+
# Brokes string identifier to numeric tokens in array.
|
94
|
+
#
|
95
|
+
# @param [String, Symbol] value version identifier
|
96
|
+
# @return [Array] array of tokens
|
97
|
+
#
|
98
|
+
|
99
|
+
def self.broke(string)
|
100
|
+
string.to_s.split(".").map! { |i| i.to_i }
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
##
|
105
|
+
# Contents frozen tokens array of the current ruby version.
|
106
|
+
# @see VERSION
|
107
|
+
#
|
108
|
+
|
109
|
+
TOKENS = self::broke(self::VERSION).freeze
|
110
|
+
|
111
|
+
##
|
112
|
+
# Universal comparing routine for all type of (in)equalities.
|
113
|
+
#
|
114
|
+
|
115
|
+
private
|
116
|
+
def self.__compare(value, lower, higher, equal)
|
117
|
+
if not value.kind_of? Array
|
118
|
+
value = self.broke(value.to_s)
|
119
|
+
end
|
120
|
+
|
121
|
+
self::TOKENS.each_index do |i|
|
122
|
+
case self::TOKENS[i].to_i.compare(value[i].to_i)
|
123
|
+
when -1
|
124
|
+
return lower
|
125
|
+
when 1
|
126
|
+
return higher
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
return equal
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
data/test
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
4
|
+
|
5
|
+
$:.push("./lib")
|
6
|
+
require "ruby-version"
|
7
|
+
require "riot"
|
8
|
+
|
9
|
+
DOWN = :"1.8.7"
|
10
|
+
CURRENT = :"1.9.2"
|
11
|
+
UP = :"2.0.1"
|
12
|
+
|
13
|
+
context "Ruby::Version" do
|
14
|
+
asserts("#<") do
|
15
|
+
Ruby::Version < UP and not Ruby::Version < DOWN and not Ruby::Version < CURRENT
|
16
|
+
end
|
17
|
+
asserts("#<=") do
|
18
|
+
Ruby::Version <= UP and not Ruby::Version <= DOWN and Ruby::Version <= CURRENT
|
19
|
+
end
|
20
|
+
asserts("#==") do
|
21
|
+
not Ruby::Version == UP and not Ruby::Version == DOWN and Ruby::Version == CURRENT
|
22
|
+
end
|
23
|
+
asserts("#>") do
|
24
|
+
not Ruby::Version > UP and Ruby::Version > DOWN and not Ruby::Version > CURRENT
|
25
|
+
end
|
26
|
+
asserts("#>=") do
|
27
|
+
not Ruby::Version >= UP and Ruby::Version >= DOWN and Ruby::Version >= CURRENT
|
28
|
+
end
|
29
|
+
asserts("#TOKENS") do
|
30
|
+
Ruby::Version::TOKENS == Ruby::Version::broke(RUBY_VERSION)
|
31
|
+
end
|
32
|
+
asserts("#VERSION") do
|
33
|
+
Ruby::Version::VERSION == RUBY_VERSION
|
34
|
+
end
|
35
|
+
asserts("#broke") do
|
36
|
+
Ruby::Version::broke("1.2.3") == [1, 2, 3]
|
37
|
+
end
|
38
|
+
asserts("#compare") do
|
39
|
+
Ruby::Version::compare(DOWN) == 1 and Ruby::Version::compare(CURRENT) == 0 and Ruby::Version::compare(UP) == -1
|
40
|
+
end
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- "Martin Koz\xC3\xA1k"
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-06-23 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hash-utils
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.16.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: bundler
|
28
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: jeweler
|
39
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 1.5.2
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: riot
|
50
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.12.3
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *id004
|
59
|
+
description:
|
60
|
+
email: martinkozak@martinkozak.net
|
61
|
+
executables: []
|
62
|
+
|
63
|
+
extensions: []
|
64
|
+
|
65
|
+
extra_rdoc_files:
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
files:
|
69
|
+
- .document
|
70
|
+
- Gemfile
|
71
|
+
- Gemfile.lock
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- VERSION
|
76
|
+
- lib/ruby-version.rb
|
77
|
+
- test
|
78
|
+
homepage: http://github.com/martinkozak/ruby-version
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
hash: -1080418548201158678
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
version: "0"
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: "0"
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.8.5
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: Serves as wrapper module for the RUBY_VERSION constant with matching the version numbers.
|
108
|
+
test_files: []
|
109
|
+
|