Class: RD::Version

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, major, minor, patch_level) ⇒ Version

Returns a new instance of Version.



14
15
16
17
18
19
# File 'lib/rd/version.rb', line 14

def initialize(name, major, minor, patch_level)
  @name = name
  @major = major
  @minor = minor
  @patch_level = patch_level
end

Instance Attribute Details

#majorObject (readonly)

Returns the value of attribute major.



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

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



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

def minor
  @minor
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#patch_levelObject (readonly)

Returns the value of attribute patch_level.



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

def patch_level
  @patch_level
end

Class Method Details

.analyze_version_string(version_str) ⇒ Object



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

def Version.analyze_version_string(version_str)
  version_str = clean_up_version_string(version_str)
  version_str.split(/\./).collect{|i| i.to_i }
end

.clean_up_version_string(version_str) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/rd/version.rb', line 33

def Version.clean_up_version_string(version_str)
  if /^\$Version:?\s*(.*)\$/ === version_str
	$1
  else
	version_str
  end
end

.new_from_version_string(name, version_str) ⇒ Object



9
10
11
12
# File 'lib/rd/version.rb', line 9

def Version.new_from_version_string(name, version_str)
  major, minor, patch_level, *dummy = analyze_version_string(version_str)
  return Version.new(name, major, minor, patch_level)
end

Instance Method Details

#to_sObject



26
27
28
29
30
31
# File 'lib/rd/version.rb', line 26

def to_s
  result = sprintf("%s %d", @name, @major)
  result += sprintf(".%d", @minor) if @minor
  result += sprintf(".%d", @patch_level) if @patch_level
  result
end