Class: SystemCat::Version
- Inherits:
-
Object
- Object
- SystemCat::Version
- Defined in:
- lib/system_cat/version.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
Instance Method Summary collapse
- #bump ⇒ Object
- #decrement ⇒ Object
- #increment ⇒ Object
-
#initialize(path = 'config/version.txt') ⇒ Version
constructor
A new instance of Version.
- #save ⇒ Object
- #to_s ⇒ Object
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
#code ⇒ Object
Returns the value of attribute code.
4 5 6 |
# File 'lib/system_cat/version.rb', line 4 def code @code end |
Instance Method Details
#bump ⇒ Object
32 33 34 |
# File 'lib/system_cat/version.rb', line 32 def bump return increment.save end |
#decrement ⇒ Object
11 12 13 14 |
# File 'lib/system_cat/version.rb', line 11 def decrement @code = code - 1 return self end |
#increment ⇒ Object
16 17 18 19 |
# File 'lib/system_cat/version.rb', line 16 def increment @code = code + 1 return self end |
#save ⇒ Object
21 22 23 |
# File 'lib/system_cat/version.rb', line 21 def save File.open(@path, 'wb') { |io| io.write(@code) } end |
#to_s ⇒ Object
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 |