Class: Version
- Inherits:
-
Object
- Object
- Version
- Defined in:
- lib/atk/version.rb
Overview
create a variable for the current ruby version
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.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/atk/version.rb', line 13 def initialize(version_as_string) # if there are no digits if !(version_as_string.to_s =~ /\d/) raise " \n \n When calling Version.new(arg1)\n the `arg1.to_s` was \#{version_as_string.to_s}\n which does not contain any digits\n so the Version class doesn't know what to do with it\n HEREDOC\n end\n @levels = version_as_string.split('.')\n @comparable = @levels[0] =~ /\\A\\d+\\z/\n # convert values into integers where possible\n index = -1\n for each in @levels.dup\n index += 1\n if each =~ /\\A\\d+\\z/\n @levels[index] = each.to_i\n end\n end\n @major, @minor, @patch, *_ = @levels\nend\n".remove_indent |
Instance Attribute Details
#codename ⇒ Object
Returns the value of attribute codename.
4 5 6 |
# File 'lib/atk/version.rb', line 4 def codename @codename end |
#levels ⇒ Object
Returns the value of attribute levels.
4 5 6 |
# File 'lib/atk/version.rb', line 4 def levels @levels end |
Class Method Details
.extract_from(string) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/atk/version.rb', line 6 def self.extract_from(string) match = string.match(/\d+\.\d+(\.\d+)*/) if match != nil return Version.new(match[0]) end end |
Instance Method Details
#!=(other_version) ⇒ Object
111 112 113 114 |
# File 'lib/atk/version.rb', line 111 def !=(other_version) value = (self <=> other_version) return value && value != 0 end |
#<(other_version) ⇒ Object
91 92 93 94 |
# File 'lib/atk/version.rb', line 91 def <(other_version) value = (self <=> other_version) return value && value == -1 end |
#<=(other_version) ⇒ Object
106 107 108 109 |
# File 'lib/atk/version.rb', line 106 def <=(other_version) value = (self <=> other_version) return value && value != 1 end |
#<=>(other_version) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/atk/version.rb', line 55 def <=>(other_version) if not other_version.is_a?(Version) raise "When doing version comparision, both sides must be a version object" 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 if self_levels.size > other_levels.size return 1 elsif self_levels.size < other_levels.size return -1 else return 0 end end comparision = self_levels.shift() <=> other_levels.shift() if comparision != 0 return comparision end end else return nil end end |
#==(other_version) ⇒ Object
96 97 98 99 |
# File 'lib/atk/version.rb', line 96 def ==(other_version) value = (self <=> other_version) return value && value == 0 end |
#>(other_version) ⇒ Object
86 87 88 89 |
# File 'lib/atk/version.rb', line 86 def >(other_version) value = (self <=> other_version) return value && value == 1 end |
#>=(other_version) ⇒ Object
101 102 103 104 |
# File 'lib/atk/version.rb', line 101 def >=(other_version) value = (self <=> other_version) return value && value != -1 end |
#comparable? ⇒ Boolean
51 52 53 |
# File 'lib/atk/version.rb', line 51 def comparable? return @comparable end |
#major ⇒ Object
46 |
# File 'lib/atk/version.rb', line 46 def major() @major end |
#major=(new_value) ⇒ Object
47 48 49 |
# File 'lib/atk/version.rb', line 47 def major=(new_value) @levels[0] = new_value end |
#minor ⇒ Object
42 |
# File 'lib/atk/version.rb', line 42 def minor() @minor end |
#minor=(new_value) ⇒ Object
43 44 45 |
# File 'lib/atk/version.rb', line 43 def minor=(new_value) @levels[1] = new_value end |
#patch ⇒ Object
38 |
# File 'lib/atk/version.rb', line 38 def patch() @patch end |
#patch=(new_value) ⇒ Object
39 40 41 |
# File 'lib/atk/version.rb', line 39 def patch=(new_value) @levels[2] = new_value end |
#to_s ⇒ Object
116 117 118 |
# File 'lib/atk/version.rb', line 116 def to_s return @levels.map(&:to_s).join('.') end |