k-versionify 0.1.1

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/README.md ADDED
@@ -0,0 +1,13 @@
1
+ Parser for versions strings such as `"1.2.3"`.
2
+
3
+ Usage:
4
+
5
+ require 'versionify'
6
+
7
+ V = Versionify::VersionSpec
8
+
9
+ puts ( "1.0.10" > "1.0.2" ) # => false
10
+ puts (V.new("1.0.10") > V.new("1.0.2")) # => true
11
+
12
+ Author: Philipp Kempgen, [http://kempgen.net](http://kempgen.net)
13
+
data/lib/versionify.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'versionify/version_spec'
2
+
@@ -0,0 +1,197 @@
1
+ module Versionify
2
+ class VersionSpec < ::Array
3
+
4
+ # Get rid of methods from Array that we don't want.
5
+ #OPTIMIZE Remove all inherited methods, except some selected ones?
6
+ [ # (In Ruby 2.0 we could use %i() notation for an array of symbols.)
7
+ :'-',
8
+ :'*',
9
+ :'&',
10
+ :'+',
11
+ :'<<',
12
+ :'|',
13
+ :assoc,
14
+ :clear,
15
+ :collect!,
16
+ :compact!,
17
+ :concat,
18
+ :delete,
19
+ :delete_at,
20
+ :delete_if,
21
+ :drop,
22
+ :drop_while,
23
+ :fill,
24
+ :flatten,
25
+ :flatten!,
26
+ :include?,
27
+ :index,
28
+ :insert,
29
+ :keep_if,
30
+ :map!,
31
+ :pop,
32
+ :push,
33
+ :rassoc,
34
+ :reject!,
35
+ :replace,
36
+ :reverse!,
37
+ :rindex,
38
+ :rotate!,
39
+ :sample,
40
+ :select!,
41
+ :shift,
42
+ :shuffle!,
43
+ :sort,
44
+ :sort!,
45
+ :sort_by!,
46
+ :uniq,
47
+ :uniq!,
48
+ :zip,
49
+ ].each { |m|
50
+ #undef m if self.superclass.new.respond_to?( m )
51
+ #define_method( m ) { |*args|
52
+ # raise ::NoMethodError, "Method #{m}() isn't allowed for #{self.class.name.split('::').last}."
53
+ #}
54
+ undef_method( m ) if self.superclass.new.respond_to?( m ) #OPTIMIZE
55
+ }
56
+
57
+ #puts "CLASS: #{self.superclass.new.respond_to?( :'+' )} "
58
+
59
+
60
+ include ::Comparable
61
+
62
+ NONE_STR = 'none'.freeze # / 'unknown'
63
+
64
+ # v = VersionSpec.new( '1.2.3' )
65
+ # v = VersionSpec.new( nil )
66
+ # v = VersionSpec.new( false )
67
+ def initialize( arg )
68
+ if arg
69
+ if arg.kind_of?( ::String )
70
+ parts = arg.to_s.strip.split('.').map( & :to_i )
71
+ elsif arg.kind_of?( ::Array )
72
+ parts = arg.map( & :to_i )
73
+ else
74
+ raise ::ArgumentError.new( "Expected a String or Array, #{arg.class.name} given." )
75
+ end
76
+ else
77
+ parts = []
78
+ end
79
+
80
+ super( parts )
81
+ end
82
+
83
+ ## v = VersionSpec.parse( '1.2.3' )
84
+ #def self.parse( arg )
85
+ # self.new( arg )
86
+ #end
87
+
88
+ def null?
89
+ #self.count == 0
90
+ self.empty?
91
+ end
92
+
93
+ def comparable?
94
+ ! self.null?
95
+ end
96
+
97
+ def ==( other )
98
+ cmp = (self <=> other)
99
+ #return case cmp
100
+ # when 0 ; true
101
+ # when [-1,1] ; false
102
+ # when nil ; false
103
+ # else ; false
104
+ #end
105
+ return cmp == 0
106
+ end
107
+
108
+ def !=( other )
109
+ return ! (self == other)
110
+ end
111
+
112
+ def <=>( other )
113
+ if other.kind_of?( ::String )
114
+ other = self.class.new( other )
115
+ end
116
+ return nil if (! other.kind_of?( self.class ))
117
+ return nil if (null? || other.null?)
118
+ super
119
+ end
120
+
121
+ def join( separator='.' )
122
+ super( separator )
123
+ end
124
+
125
+ def to_s
126
+ self.join('.')
127
+ end
128
+
129
+ def inspect
130
+ "%s( %s )" % [ self.class.name, self.to_s.inspect ]
131
+ end
132
+
133
+ # Like to_s(), but don't return an empty string in case
134
+ # there are no parts.
135
+ def to_display
136
+ comparable? ? self.to_s : NONE_STR
137
+ end
138
+
139
+ def to_s_nil
140
+ comparable? ? self.to_s : nil
141
+ end
142
+
143
+ def empty?
144
+ super
145
+ end
146
+
147
+ def to_a
148
+ super
149
+ end
150
+
151
+ def to_ary
152
+ to_a
153
+ end
154
+
155
+ def length
156
+ super
157
+ end
158
+ alias :size :length
159
+ alias :count :length
160
+
161
+ def slice( *args )
162
+ super
163
+ end
164
+
165
+ def at( index )
166
+ super
167
+ end
168
+
169
+ def fetch( idx, *args )
170
+ super
171
+ end
172
+
173
+ def pack( fmt )
174
+ super
175
+ end
176
+
177
+ def frozen?
178
+ super
179
+ end
180
+
181
+ def freeze
182
+ super
183
+ end
184
+
185
+ def freeze!
186
+ freeze
187
+ end
188
+
189
+ #OPTIMIZE Implement first(...), last(...)
190
+
191
+ end
192
+
193
+ def VersionSpec( arg )
194
+ VersionSpec.new( arg )
195
+ end
196
+ end
197
+
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: k-versionify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Philipp Kempgen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: test-unit
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.5'
22
+ - - ! '>='
23
+ - !ruby/object:Gem::Version
24
+ version: 2.5.0
25
+ type: :development
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '2.5'
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: 2.5.0
36
+ description: Parser for version strings such as "1.2.3".
37
+ email:
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - lib/versionify/version_spec.rb
43
+ - lib/versionify.rb
44
+ - README.md
45
+ homepage: https://github.com/philipp-kempgen/versionify
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.25
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Parser for version strings.
69
+ test_files: []
70
+ has_rdoc: