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
112 113 114 115 |
# File 'lib/atk/version.rb', line 112 def !=(other_version) value = (self <=> other_version) return value && value != 0 end |
#<(other_version) ⇒ Object
92 93 94 95 |
# File 'lib/atk/version.rb', line 92 def <(other_version) value = (self <=> other_version) return value && value == -1 end |
#<=(other_version) ⇒ Object
107 108 109 110 |
# File 'lib/atk/version.rb', line 107 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 85 |
# File 'lib/atk/version.rb', line 55 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 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
97 98 99 100 |
# File 'lib/atk/version.rb', line 97 def ==(other_version) value = (self <=> other_version) return value && value == 0 end |
#>(other_version) ⇒ Object
87 88 89 90 |
# File 'lib/atk/version.rb', line 87 def >(other_version) value = (self <=> other_version) return value && value == 1 end |
#>=(other_version) ⇒ Object
102 103 104 105 |
# File 'lib/atk/version.rb', line 102 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
117 118 119 |
# File 'lib/atk/version.rb', line 117 def to_s return @levels.map(&:to_s).join('.') end |