Class: Jison::Version

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/jison/version.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(major, minor = 0, micro = 0) ⇒ Version

Returns a new instance of Version.



12
13
14
# File 'lib/jison/version.rb', line 12

def initialize(major, minor=0, micro=0)
  @major, @minor, @micro = major, minor, micro
end

Instance Attribute Details

#majorObject (readonly)

Returns the value of attribute major.



5
6
7
# File 'lib/jison/version.rb', line 5

def major
  @major
end

#microObject (readonly)

Returns the value of attribute micro.



5
6
7
# File 'lib/jison/version.rb', line 5

def micro
  @micro
end

#minorObject (readonly)

Returns the value of attribute minor.



5
6
7
# File 'lib/jison/version.rb', line 5

def minor
  @minor
end

Class Method Details

.from_string(string) ⇒ Object



7
8
9
10
# File 'lib/jison/version.rb', line 7

def self.from_string(string)
  version = string.gsub(/^\s+|\s+$/, '').split('.').map(&:to_i)
  new(*version)
end

Instance Method Details

#<=>(other) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/jison/version.rb', line 22

def <=>(other)
  case other
  when Version
    cmp = major - other.major
    return cmp unless cmp.zero?
    cmp = minor - other.minor
    return cmp unless cmp.zero?
    micro - other.micro
  when String
    self <=> Version.from_string(other)
  when Fixnum
    major - other
  else
    raise RuntimeError.new("Cannot compare against #{other.class}: #{other.inspect}")
  end
end

#==(other) ⇒ Object



16
17
18
19
20
# File 'lib/jison/version.rb', line 16

def ==(other)
  major == other.major \
    && minor == other.minor \
    && micro == other.micro
end

#to_sObject



39
40
41
# File 'lib/jison/version.rb', line 39

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