Class: SpecVersion
- Includes:
- Comparable
- Defined in:
- lib/extensions/mspec/mspec/utils/version.rb
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(version, ceil = false) ⇒ SpecVersion
constructor
SpecVersion handles comparison correctly for the context by filling in missing version parts according to the value of
ceil. -
#to_i ⇒ Object
Converts a string representation of a version major.minor.tiny to an integer representation so that comparisons can be made.
- #to_int ⇒ Object
- #to_s ⇒ Object
- #to_str ⇒ Object
Constructor Details
#initialize(version, ceil = false) ⇒ SpecVersion
SpecVersion handles comparison correctly for the context by filling in missing version parts according to the value of ceil. If ceil is false, 0 digits fill in missing version parts. If ceil is true, 9 digits fill in missing parts. (See e.g. VersionGuard and BugGuard.)
10 11 12 13 14 |
# File 'lib/extensions/mspec/mspec/utils/version.rb', line 10 def initialize(version, ceil = false) @version = version @ceil = ceil @integer = nil end |
Instance Method Details
#<=>(other) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/extensions/mspec/mspec/utils/version.rb', line 43 def <=>(other) if other.respond_to? :to_int other = Integer other else other = SpecVersion.new(String(other)).to_i end self.to_i <=> other end |
#to_i ⇒ Object
Converts a string representation of a version major.minor.tiny to an integer representation so that comparisons can be made. For example, “2.2.10” < “2.2.2” would be false if compared as strings.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/extensions/mspec/mspec/utils/version.rb', line 27 def to_i unless @integer major, minor, tiny = @version.split "." if @ceil tiny = 99 unless tiny end parts = [major, minor, tiny].map { |x| x.to_i } @integer = ("1%02d%02d%02d" % parts).to_i end @integer end |
#to_int ⇒ Object
39 40 41 |
# File 'lib/extensions/mspec/mspec/utils/version.rb', line 39 def to_int to_i end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/extensions/mspec/mspec/utils/version.rb', line 16 def to_s @version end |
#to_str ⇒ Object
20 21 22 |
# File 'lib/extensions/mspec/mspec/utils/version.rb', line 20 def to_str to_s end |