Class: SystemCat::Version

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = 'config/version.txt') ⇒ Version

Returns a new instance of Version.



6
7
8
9
# File 'lib/system_cat/version.rb', line 6

def initialize(path = 'config/version.txt')
  @path = path
  @code = File.read(@path).to_i
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



4
5
6
# File 'lib/system_cat/version.rb', line 4

def code
  @code
end

Instance Method Details

#bumpObject



32
33
34
# File 'lib/system_cat/version.rb', line 32

def bump
  return increment.save
end

#decrementObject



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

def decrement
  @code = code - 1
  return self
end

#incrementObject



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

def increment
  @code = code + 1
  return self
end

#saveObject



21
22
23
# File 'lib/system_cat/version.rb', line 21

def save
  File.open(@path, 'wb') { |io| io.write(@code) }
end

#to_sObject



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

def to_s
  major = (code / 100).to_i
  minor = ((code % 100) / 10).to_i
  build = code % 10
  return "#{major}.#{minor}.#{build}"
end