Class: Spruz::StringVersion::Version

### Home Classes Methods

### In Files

- lib/spruz/string_version.rb

### Parent

Object

### Methods

- ::new
- #<=>
- #==
- #[]
- #[]=
- #array
- #build
- #build=
- #inspect
- #major
- #major=
- #minor
- #minor=
- #pred!
- #revision
- #revision=
- #succ!
- #to_a
- #to_s
- #version

### Included Modules

- Comparable

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Spruz
- Spruz::Attempt
- Spruz::Bijection
- Spruz::Blank
- Spruz::Blank::Array
- Spruz::Blank::FalseClass
- Spruz::Blank::Hash
- Spruz::Blank::NilClass
- Spruz::Blank::Numeric
- Spruz::Blank::Object
- Spruz::Blank::String
- Spruz::Blank::TrueClass
- Spruz::CountBy
- Spruz::DeepDup
- Spruz::FileBinary
- Spruz::FileBinary::ClassMethods
- Spruz::FileBinary::Constants
- Spruz::Full
- Spruz::GO
- Spruz::Generator
- Spruz::HashSymbolizeKeysRecursive
- Spruz::HashUnion
- Spruz::Limited
- Spruz::LinesFile
- Spruz::LinesFile::LineExtension
- Spruz::Memoize
- Spruz::Minimize
- Spruz::ModuleGroup
- Spruz::Null
- Spruz::Once
- Spruz::P
- Spruz::PartialApplication
- Spruz::RangePlus
- Spruz::Round
- Spruz::SecureWrite
- Spruz::Shuffle
- Spruz::StringCamelize
- Spruz::StringUnderscore
- Spruz::StringVersion
- Spruz::StringVersion::Version
- Spruz::Subhash
- Spruz::TimeDummy
- Spruz::TimeDummy::ClassMethods
- Spruz::ToProc
- Spruz::UniqBy
- Spruz::Write
- Array
- Enumerable
- File
- Float
- Hash
- IO
- IRB
- Integer
- Method
- Module
- Object
- Proc
- Range
- String
- Symbol
- Time

No matching classes.

# Spruz::StringVersion::Version

### Public Class Methods

new(string) click to toggle source

    # File lib/spruz/string_version.rb, line 8
    def initialize(string)
      string =~ /\A[\.\d]+\Z/ or raise ArgumentError, "#{string.inspect} isn't a version number"
      @version = string.frozen? ? string.dup : string
    end

### Public Instance Methods

<=>(other) click to toggle source

    # File lib/spruz/string_version.rb, line 67
    def <=>(other)
      pairs = array.zip(other.array)
      pairs.map! { |a, b| [ a.nil? ? 0 : a, b.nil? ? 0 : b ] }
      a, b = pairs.transpose
      a <=> b
    end

==(other) click to toggle source

    # File lib/spruz/string_version.rb, line 74
    def ==(other)
      (self <=> other).zero?
    end

[](index) click to toggle source

    # File lib/spruz/string_version.rb, line 45
    def [](index)
      array[index]
    end

[]=(index, value) click to toggle source

    # File lib/spruz/string_version.rb, line 49
    def []=(index, value)
      value = value.to_i
      value >= 0 or raise ArgumentError, "version numbers can't contain negative numbers like #{value}"
      a = array
      @array = nil
      a[index] = value
      a.map! { |x| x.nil? ? 0 : x }
      @version.replace a * '.'
    end

array() click to toggle source

    # File lib/spruz/string_version.rb, line 78
    def array
       @version.split('.').map(&:to_i)
    end

Also aliased as: to_a
build() click to toggle source

    # File lib/spruz/string_version.rb, line 29
    def build
      self[2]
    end

build=(number) click to toggle source

    # File lib/spruz/string_version.rb, line 33
    def build=(number)
      self[2] = number
    end

inspect() click to toggle source
Alias for: to_s
major() click to toggle source

    # File lib/spruz/string_version.rb, line 13
    def major
      self[0]
    end

major=(number) click to toggle source

    # File lib/spruz/string_version.rb, line 17
    def major=(number)
      self[0] = number
    end

minor() click to toggle source

    # File lib/spruz/string_version.rb, line 21
    def minor
      self[1]
    end

minor=(number) click to toggle source

    # File lib/spruz/string_version.rb, line 25
    def minor=(number)
      self[1] = number
    end

pred!() click to toggle source

    # File lib/spruz/string_version.rb, line 63
    def pred!
      self[-1] -= 1
    end

revision() click to toggle source

    # File lib/spruz/string_version.rb, line 37
    def revision
      self[3]
    end

revision=(number) click to toggle source

    # File lib/spruz/string_version.rb, line 41
    def revision=(number)
      self[3] = number
    end

succ!() click to toggle source

    # File lib/spruz/string_version.rb, line 59
    def succ!
      self[-1] += 1
    end

to_a() click to toggle source
Alias for: array
to_s() click to toggle source

    # File lib/spruz/string_version.rb, line 84
    def to_s
      @version
    end

Also aliased as: inspect
version() click to toggle source

    # File lib/spruz/string_version.rb, line 90
    def version
      self
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.