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

Returns a new instance of VersionTag.



26
27
28
29
30
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 26

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.



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

def admin
  @admin
end

#majorObject (readonly)

Returns the value of attribute major.



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

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



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

def minor
  @minor
end

Class Method Details

.parse(raw_tag) ⇒ Object

Parameters:

  • raw_tag (String)

    the value of the tag attribute from a Version node



20
21
22
23
24
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 20

def self.parse(raw_tag)
  return nil unless raw_tag =~ /(\d+)\.(\d+)\.(\d+)/

  VersionTag.new $1, $2, $3
end

Instance Method Details

#<=>(other) ⇒ Object



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

def <=>(other)
  diff = @major <=> other.major
  return diff if diff != 0

  diff = @minor <=> other.minor
  return diff if diff != 0

  @admin <=> other.admin
end

#increment(sig) ⇒ Object

Parameters:

  • sig (Symbol)

    which part of the version tag to increment :major, :minor, :admin



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

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



49
50
51
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 49

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