Class: Versionifier::Version

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(the_version) ⇒ Version

Returns a new instance of Version.



6
7
8
9
10
11
# File 'lib/versionifier/version.rb', line 6

def initialize(the_version)
  splitted    = the_version.split "."
  @major      = splitted[0].to_i
  @regular    = splitted[1].to_i
  @minor      = splitted[2].to_i
end

Instance Attribute Details

#majorObject

Returns the value of attribute major.



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

def major
  @major
end

#minorObject

Returns the value of attribute minor.



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

def minor
  @minor
end

#regularObject

Returns the value of attribute regular.



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

def regular
  @regular
end

Instance Method Details

#==(other) ⇒ Object



36
37
38
# File 'lib/versionifier/version.rb', line 36

def ==(other)
  return self.eql? other
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
# File 'lib/versionifier/version.rb', line 28

def eql?(other)
  if other.is_a? String
    return other == self.to_s
  else
    return super other
  end
end

#increment(which, quant, options = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/versionifier/version.rb', line 13

def increment(which, quant, options = nil)
  new_version = self.clone
  new_version.send "#{which}=".to_sym, self.send(which) + quant
  if options == :reset
    case which
      when :major
        new_version.regular = 0; new_version.minor = 0
      when :regular
        new_version.minor = 0
    end
  end
  new_version
end

#to_sObject



27
# File 'lib/versionifier/version.rb', line 27

def to_s; "#{@major}.#{@regular}.#{@minor}"; end