Class: Dor::VersionTag

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/dor/datastreams/version_metadata_ds.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(maj, min, adm) ⇒ VersionTag


24
25
26
27
28
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 24

def initialize(maj, min, adm)
  @major = maj.to_i
  @minor = min.to_i
  @admin = adm.to_i
end

Instance Attribute Details

#adminObject (readonly)

Returns the value of attribute admin


6
7
8
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 6

def admin
  @admin
end

#majorObject (readonly)

Returns the value of attribute major


6
7
8
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 6

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor


6
7
8
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 6

def minor
  @minor
end

Class Method Details

.parse(raw_tag) ⇒ Object


17
18
19
20
21
22
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 17

def self.parse(raw_tag)
  unless(raw_tag =~ /(\d+)\.(\d+)\.(\d+)/)
    return nil
  end
  VersionTag.new $1, $2, $3
end

Instance Method Details

#<=>(anOther) ⇒ Object


8
9
10
11
12
13
14
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 8

def <=>(anOther)
  diff = @major <=> anOther.major
  return diff if diff != 0
  diff = @minor <=> anOther.minor
  return diff if diff != 0
  @admin <=> anOther.admin
end

#increment(sig) ⇒ Object


32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 32

def increment(sig)
  case sig
  when :major
    @major += 1
    @minor = 0
    @admin = 0
  when :minor
    @minor += 1
    @admin = 0
  when :admin
    @admin += 1
  end
  self
end

#to_sObject


47
48
49
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 47

def to_s
  "#{@major.to_s}.#{@minor.to_s}.#{admin.to_s}"
end