Class: ZMQ::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/0mq/version.rb

Overview

libzmq library version.

Class Method Summary collapse

Class Method Details

.!=(value) ⇒ Object

:nodoc:



74
75
76
# File 'lib/0mq/version.rb', line 74

def !=(value)
  (self <=> value) != 0 ? true : false
end

.<(value) ⇒ Object

:nodoc:



89
90
91
# File 'lib/0mq/version.rb', line 89

def <(value)
  (self <=> value) == -1 ? true : false
end

.<=(value) ⇒ Object

:nodoc:



94
95
96
# File 'lib/0mq/version.rb', line 94

def <=(value)
  (self <=> value) != 1 ? true : false
end

.<=>(value) ⇒ Object

Compare this version to another version. Examples: “3.2.0”, “3.2”, “3”, 3



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/0mq/version.rb', line 46

def <=>(value)
  expression = /(?<major>\d+)(\.(?<minor>\d+))?(\.(?<patch>\d+))?/
  
  # Convert both versions into an array of [major, minor, patch].
  this_version = self.to_s
  other_version = value.to_s
  
  this_version =~ expression
  this_set = $~.captures.map { |item| item.to_i if item }.select { |item| item }
  
  other_version =~ expression
  other_set = $~.captures.map { |item| item.to_i if item }.select { |item| item }
  
  # Compare each section (major/minor/patch) of the version number.
  other_set.count.times do |i|
    return  1 if this_set[i] > other_set[i]
    return -1 if this_set[i] < other_set[i]
  end
  
  0 # If the iterator didn't return, the versions are equal.
end

.==(value) ⇒ Object

:nodoc:



69
70
71
# File 'lib/0mq/version.rb', line 69

def ==(value)
  (self <=> value) == 0 ? true : false
end

.>(value) ⇒ Object

:nodoc:



79
80
81
# File 'lib/0mq/version.rb', line 79

def >(value)
  (self <=> value) == 1 ? true : false
end

.>=(value) ⇒ Object

:nodoc:



84
85
86
# File 'lib/0mq/version.rb', line 84

def >=(value)
  (self <=> value) != -1 ? true : false
end

.inspectObject

:nodoc:



40
41
42
# File 'lib/0mq/version.rb', line 40

def inspect
  "#{super} \"#{to_s}\""
end

.majorObject

:nodoc:



20
21
22
# File 'lib/0mq/version.rb', line 20

def major
  @version[:major]
end

.minorObject

:nodoc:



25
26
27
# File 'lib/0mq/version.rb', line 25

def minor
  @version[:minor]
end

.patchObject

:nodoc:



30
31
32
# File 'lib/0mq/version.rb', line 30

def patch
  @version[:patch]
end

.to_sObject

:nodoc:



35
36
37
# File 'lib/0mq/version.rb', line 35

def to_s
  "#{major}.#{minor}.#{patch}"
end