Class: AssUpdater::AssVersion
- Inherits:
-
Object
- Object
- AssUpdater::AssVersion
- Defined in:
- lib/ass_updater/ass_version.rb
Overview
Class implement 1C version numbering. 1C version consist from 4 digt group. Major 1st and 2nd group called Redaction.
Instance Attribute Summary collapse
-
#_1 ⇒ Fixrnum
readonly
Value of digit group.
-
#_2 ⇒ Fixrnum
readonly
Value of digit group.
-
#_3 ⇒ Fixrnum
readonly
Value of digit group.
-
#_4 ⇒ Fixrnum
readonly
Value of digit group.
Class Method Summary collapse
-
.convert_array(a) ⇒ Array<AssUpdater::AssVersion>
Convert [Array<String>] to [Array<AssUpdater::AssVersion>].
-
.zerro_version ⇒ AssUpdater::AssVersion
Return zerro vesion number ‘0.0.0.0’.
Instance Method Summary collapse
-
#<(other) ⇒ Boollean
Compare versions.
-
#<=(other) ⇒ Boollean
Compare versions.
-
#<=>(other) ⇒ Boollean
Compare versions.
-
#==(other) ⇒ Boollean
Compare versions.
-
#>(other) ⇒ Boollean
Compare versions.
-
#>=(other) ⇒ Boollean
Compare versions.
-
#initialize(v = nil) ⇒ AssVersion
constructor
A new instance of AssVersion.
-
#redaction ⇒ String
Return redaction number.
-
#to_a ⇒ Array<Fixnum>
Conver version to array of digit group.
-
#to_s ⇒ Stgring
Convert version to string.
-
#zerro? ⇒ Boolean
Return true if it is zerro version see AssVersion.zerro_version.
Constructor Details
#initialize(v = nil) ⇒ AssVersion
Returns a new instance of AssVersion.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ass_updater/ass_version.rb', line 33 def initialize(v = nil) v ||= '0.0.0.0' unless v.to_s =~ /^(\d)+\.(\d+)\.(\d+)\.(\d+)$/ fail ArgumentError, "Invalid version string `#{v}'. Expect 'd.d.d.d' format" end @_1 = Regexp.last_match(1).to_i @_2 = Regexp.last_match(2).to_i @_3 = Regexp.last_match(3).to_i @_4 = Regexp.last_match(4).to_i end |
Instance Attribute Details
#_1 ⇒ Fixrnum (readonly)
Value of digit group
7 8 9 |
# File 'lib/ass_updater/ass_version.rb', line 7
def _1
@_1
end
|
#_2 ⇒ Fixrnum (readonly)
Value of digit group
7 8 9 |
# File 'lib/ass_updater/ass_version.rb', line 7
def _2
@_2
end
|
#_3 ⇒ Fixrnum (readonly)
Value of digit group
7 8 9 |
# File 'lib/ass_updater/ass_version.rb', line 7
def _3
@_3
end
|
#_4 ⇒ Fixrnum (readonly)
Value of digit group
7 8 9 |
# File 'lib/ass_updater/ass_version.rb', line 7
def _4
@_4
end
|
Class Method Details
.convert_array(a) ⇒ Array<AssUpdater::AssVersion>
Convert [Array<String>] to [Array<AssUpdater::AssVersion>]
18 19 20 21 22 |
# File 'lib/ass_updater/ass_version.rb', line 18 def convert_array(a) a.map do |i| new(i) end end |
.zerro_version ⇒ AssUpdater::AssVersion
Return zerro vesion number ‘0.0.0.0’
12 13 14 |
# File 'lib/ass_updater/ass_version.rb', line 12 def zerro_version new('0.0.0.0') end |
Instance Method Details
#<(other) ⇒ Boollean
Compare versions
87 88 89 |
# File 'lib/ass_updater/ass_version.rb', line 87 def <(other) (self <=> other) == -1 end |
#<=(other) ⇒ Boollean
Compare versions
97 98 99 |
# File 'lib/ass_updater/ass_version.rb', line 97 def <=(other) (self <=> other) <= 0 end |
#<=>(other) ⇒ Boollean
Compare versions
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ass_updater/ass_version.rb', line 65 def <=>(other) merge(other).each do |v| if v[0] > v[1] return 1 elsif v[0] < v[1] return -1 end end 0 end |
#==(other) ⇒ Boollean
Compare versions
77 78 79 |
# File 'lib/ass_updater/ass_version.rb', line 77 def ==(other) (self <=> other) == 0 end |
#>(other) ⇒ Boollean
Compare versions
82 83 84 |
# File 'lib/ass_updater/ass_version.rb', line 82 def >(other) (self <=> other) == 1 end |
#>=(other) ⇒ Boollean
Compare versions
92 93 94 |
# File 'lib/ass_updater/ass_version.rb', line 92 def >=(other) (self <=> other) >= 0 end |
#redaction ⇒ String
Return redaction number
59 60 61 |
# File 'lib/ass_updater/ass_version.rb', line 59 def redaction to_a.shift(2).join('.') end |
#to_a ⇒ Array<Fixnum>
Conver version to array of digit group
47 48 49 |
# File 'lib/ass_updater/ass_version.rb', line 47 def to_a [@_1, @_2, @_3, @_4] end |
#to_s ⇒ Stgring
Convert version to string
53 54 55 |
# File 'lib/ass_updater/ass_version.rb', line 53 def to_s to_a.join('.') end |
#zerro? ⇒ Boolean
Return true if it is zerro version see zerro_version
27 28 29 |
# File 'lib/ass_updater/ass_version.rb', line 27 def zerro? to_s == '0.0.0.0' end |