Class: GitSu::Version

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

Defined Under Namespace

Classes: ParseError

Constant Summary collapse

REGEX =
/(\d+)\.(\d+).(\d+)/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(major, minor, patch) ⇒ Version

Returns a new instance of Version.



46
47
48
# File 'lib/gitsu/version.rb', line 46

def initialize(major, minor, patch)
    @major, @minor, @patch = major, minor, patch
end

Instance Attribute Details

#majorObject (readonly)

Returns the value of attribute major.



45
46
47
# File 'lib/gitsu/version.rb', line 45

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



45
46
47
# File 'lib/gitsu/version.rb', line 45

def minor
  @minor
end

#patchObject (readonly)

Returns the value of attribute patch.



45
46
47
# File 'lib/gitsu/version.rb', line 45

def patch
  @patch
end

Class Method Details

.currentObject



31
32
33
# File 'lib/gitsu/version.rb', line 31

def self.current
    Version.parse(VERSION)
end

.parse(string) ⇒ Object

Raises:



25
26
27
28
29
# File 'lib/gitsu/version.rb', line 25

def self.parse(string)
    raise ParseError, "Couldn't parse string '#{string}' as version" unless REGEX =~ string
    parts = REGEX.match(string)[1..3].map {|e| e.to_i }
    Version.new(*parts)
end

.prompt(input, output, prompt, default) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/gitsu/version.rb', line 35

def self.prompt(input, output, prompt, default)
    output.print "#{prompt} [#{default}]: "
    value = input.gets.strip
    if value.empty?
        default
    else
        Version.parse value
    end
end

Instance Method Details

#==(other) ⇒ Object



58
59
60
# File 'lib/gitsu/version.rb', line 58

def ==(other)
    eql? other
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/gitsu/version.rb', line 62

def eql?(other)
    major = other.major && minor == other.minor && patch == other.patch
end

#next_minorObject



50
51
52
# File 'lib/gitsu/version.rb', line 50

def next_minor
    Version.new(@major, @minor + 1, 0)
end

#next_patchObject



54
55
56
# File 'lib/gitsu/version.rb', line 54

def next_patch
    Version.new(@major, @minor, @patch + 1)
end

#to_sObject



66
67
68
# File 'lib/gitsu/version.rb', line 66

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