Class: Version
- Inherits:
-
Object
- Object
- Version
- Defined in:
- lib/atk/version.rb
Instance Attribute Summary collapse
-
#codename ⇒ Object
Returns the value of attribute codename.
-
#levels ⇒ Object
Returns the value of attribute levels.
Class Method Summary collapse
Instance Method Summary collapse
- #!=(other_version) ⇒ Object
- #<(other_version) ⇒ Object
- #<=(other_version) ⇒ Object
- #<=>(other_version) ⇒ Object
- #==(other_version) ⇒ Object
- #>(other_version) ⇒ Object
- #>=(other_version) ⇒ Object
- #comparable? ⇒ Boolean
-
#initialize(version_as_string) ⇒ Version
constructor
A new instance of Version.
- #major ⇒ Object
- #major=(new_value) ⇒ Object
- #minor ⇒ Object
- #minor=(new_value) ⇒ Object
- #patch ⇒ Object
- #patch=(new_value) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(version_as_string) ⇒ Version
Returns a new instance of Version.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/atk/version.rb', line 11 def initialize(version_as_string) # if there are no digits if !(version_as_string.to_s =~ /\d/) raise <<-HEREDOC.remove_indent When calling Version.new(arg1) the `arg1.to_s` was #{version_as_string.to_s} which does not contain any digits so the Version class doesn't know what to do with it HEREDOC end @levels = version_as_string.split('.') @comparable = (@levels[0] =~ /\A\d+\z/) != nil # convert values into integers where possible index = -1 for each in @levels.dup index += 1 if each =~ /\A\d+\z/ @levels[index] = each.to_i end end @major, @minor, @patch, *_ = @levels end |
Instance Attribute Details
#codename ⇒ Object
Returns the value of attribute codename.
2 3 4 |
# File 'lib/atk/version.rb', line 2 def codename @codename end |
#levels ⇒ Object
Returns the value of attribute levels.
2 3 4 |
# File 'lib/atk/version.rb', line 2 def levels @levels end |
Class Method Details
Instance Method Details
#!=(other_version) ⇒ Object
104 105 106 107 |
# File 'lib/atk/version.rb', line 104 def !=(other_version) value = (self <=> other_version) return value && value != 0 end |
#<(other_version) ⇒ Object
84 85 86 87 |
# File 'lib/atk/version.rb', line 84 def <(other_version) value = (self <=> other_version) return value && value == -1 end |
#<=(other_version) ⇒ Object
99 100 101 102 |
# File 'lib/atk/version.rb', line 99 def <=(other_version) value = (self <=> other_version) return value && value != 1 end |
#<=>(other_version) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/atk/version.rb', line 53 def <=>(other_version) if not other_version.is_a?(Version) puts "When doing version comparision, both sides must be a version object" return nil end if other_version.to_s == self.to_s return 0 end if other_version.comparable? && self.comparable? self_levels = @levels.dup other_levels = other_version.levels.dup loop do if self_levels.size == 0 || other_levels.size == 0 return 0 end comparision = self_levels.shift() <=> other_levels.shift() if comparision != 0 return comparision end end else return nil end end |
#==(other_version) ⇒ Object
89 90 91 92 |
# File 'lib/atk/version.rb', line 89 def ==(other_version) value = (self <=> other_version) return value && value == 0 end |
#>(other_version) ⇒ Object
79 80 81 82 |
# File 'lib/atk/version.rb', line 79 def >(other_version) value = (self <=> other_version) return value && value == 1 end |
#>=(other_version) ⇒ Object
94 95 96 97 |
# File 'lib/atk/version.rb', line 94 def >=(other_version) value = (self <=> other_version) return value && value != -1 end |
#comparable? ⇒ Boolean
49 50 51 |
# File 'lib/atk/version.rb', line 49 def comparable? return @comparable end |
#major ⇒ Object
44 |
# File 'lib/atk/version.rb', line 44 def major() @major end |
#major=(new_value) ⇒ Object
45 46 47 |
# File 'lib/atk/version.rb', line 45 def major=(new_value) @levels[0] = new_value end |
#minor ⇒ Object
40 |
# File 'lib/atk/version.rb', line 40 def minor() @minor end |
#minor=(new_value) ⇒ Object
41 42 43 |
# File 'lib/atk/version.rb', line 41 def minor=(new_value) @levels[1] = new_value end |
#patch ⇒ Object
36 |
# File 'lib/atk/version.rb', line 36 def patch() @patch end |
#patch=(new_value) ⇒ Object
37 38 39 |
# File 'lib/atk/version.rb', line 37 def patch=(new_value) @levels[2] = new_value end |
#to_s ⇒ Object
109 110 111 |
# File 'lib/atk/version.rb', line 109 def to_s return @levels.map(&:to_s).join('.') end |