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 " \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/) != nil\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.
| 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
.extract_from(string) ⇒ Object
| 4 5 6 7 8 9 | # File 'lib/atk/version.rb', line 4 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
| 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 |