Class: Versionify::VersionSpec

Inherits:
Array
  • Object
show all
Includes:
Comparable
Defined in:
lib/versionify/version_spec.rb

Constant Summary collapse

NONE_STR =

/ ‘unknown’

'none'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(arg) ⇒ VersionSpec

v = VersionSpec.new( ‘1.2.3’ ) v = VersionSpec.new( nil ) v = VersionSpec.new( false )



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/versionify/version_spec.rb', line 67

def initialize( arg )
	if arg
		if arg.kind_of?( ::String )
			parts = arg.to_s.strip.split('.').map( & :to_i )
		elsif arg.kind_of?( ::Array )
			parts = arg.map( & :to_i )
		else
			raise ::ArgumentError.new( "Expected a String or Array, #{arg.class.name} given." )
		end
	else
		parts = []
	end
	
	super( parts )
end

Instance Method Details

#!=(other) ⇒ Object



108
109
110
# File 'lib/versionify/version_spec.rb', line 108

def !=( other )
	return ! (self == other)
end

#<=>(other) ⇒ Object



112
113
114
115
116
117
118
119
# File 'lib/versionify/version_spec.rb', line 112

def <=>( other )
	if other.kind_of?( ::String )
		other = self.class.new( other )
	end
	return nil  if (! other.kind_of?( self.class ))
	return nil  if (null? || other.null?)
	super
end

#==(other) ⇒ Object



97
98
99
100
101
102
103
104
105
106
# File 'lib/versionify/version_spec.rb', line 97

def ==( other )
	cmp = (self <=> other)
	#return case cmp
	#	when 0      ; true
	#	when [-1,1] ; false
	#	when nil    ; false
	#	else        ; false
	#end
	return cmp == 0
end

#at(index) ⇒ Object



165
166
167
# File 'lib/versionify/version_spec.rb', line 165

def at( index )
	super
end

#comparable?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/versionify/version_spec.rb', line 93

def comparable?
	! self.null?
end

#empty?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/versionify/version_spec.rb', line 143

def empty?
	super
end

#fetch(idx, *args) ⇒ Object



169
170
171
# File 'lib/versionify/version_spec.rb', line 169

def fetch( idx, *args )
	super
end

#freezeObject



181
182
183
# File 'lib/versionify/version_spec.rb', line 181

def freeze
	super
end

#freeze!Object



185
186
187
# File 'lib/versionify/version_spec.rb', line 185

def freeze!
	freeze
end

#frozen?Boolean

Returns:

  • (Boolean)


177
178
179
# File 'lib/versionify/version_spec.rb', line 177

def frozen?
	super
end

#inspectObject



129
130
131
# File 'lib/versionify/version_spec.rb', line 129

def inspect
	"%s( %s )" % [ self.class.name, self.to_s.inspect ]
end

#join(separator = '.') ⇒ Object



121
122
123
# File 'lib/versionify/version_spec.rb', line 121

def join( separator='.' )
	super( separator )
end

#lengthObject Also known as: size, count



155
156
157
# File 'lib/versionify/version_spec.rb', line 155

def length
	super
end

#null?Boolean

v = VersionSpec.parse( ‘1.2.3’ ) def self.parse( arg ) self.new( arg ) end

Returns:

  • (Boolean)


88
89
90
91
# File 'lib/versionify/version_spec.rb', line 88

def null?
	#self.count == 0
	self.empty?
end

#pack(fmt) ⇒ Object



173
174
175
# File 'lib/versionify/version_spec.rb', line 173

def pack( fmt )
	super
end

#slice(*args) ⇒ Object



161
162
163
# File 'lib/versionify/version_spec.rb', line 161

def slice( *args )
	super
end

#to_aObject



147
148
149
# File 'lib/versionify/version_spec.rb', line 147

def to_a
	super
end

#to_aryObject



151
152
153
# File 'lib/versionify/version_spec.rb', line 151

def to_ary
	to_a
end

#to_displayObject

Like to_s(), but don’t return an empty string in case there are no parts.



135
136
137
# File 'lib/versionify/version_spec.rb', line 135

def to_display
	comparable? ? self.to_s : NONE_STR
end

#to_sObject



125
126
127
# File 'lib/versionify/version_spec.rb', line 125

def to_s
	self.join('.')
end

#to_s_nilObject



139
140
141
# File 'lib/versionify/version_spec.rb', line 139

def to_s_nil
	comparable? ? self.to_s : nil
end