Class: Tins::StringVersion::Version

### Home Classes Methods

### In Files

- lib/tins/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

### Class/Module Index

Quicksearch

- Tins
- Tins
- Tins
- Tins::Annotate
- Tins::AskAndSend
- Tins::Attempt
- Tins::Bijection
- Tins::Blank
- Tins::Blank::Array
- Tins::Blank::FalseClass
- Tins::Blank::Hash
- Tins::Blank::NilClass
- Tins::Blank::Numeric
- Tins::Blank::Object
- Tins::Blank::String
- Tins::Blank::TrueClass
- Tins::BlankSlate
- Tins::BlockSelf
- Tins::CasePredicate
- Tins::ClassMethod
- Tins::Concern
- Tins::Concern::ModuleMixin
- Tins::Constant
- Tins::ConstantMaker
- Tins::CountBy
- Tins::DSLAccessor
- Tins::DateDummy
- Tins::DateTimeDummy
- Tins::DeepConstGet
- Tins::DeepDup
- Tins::Deflect
- Tins::Deflect::DeflectError
- Tins::Deflect::Deflector
- Tins::Deflect::DeflectorCollection
- Tins::Delegate
- Tins::DynamicScope
- Tins::DynamicScope::Context
- Tins::Eigenclass
- Tins::ExtractLastArgumentOptions
- Tins::FileBinary
- Tins::FileBinary::ClassMethods
- Tins::FileBinary::Constants
- Tins::Find
- Tins::Find::Finder
- Tins::Find::Finder::PathExtension
- Tins::FromModule
- Tins::Full
- Tins::GO
- Tins::GO::EnumerableExtension
- Tins::Generator
- Tins::HashSymbolizeKeysRecursive
- Tins::HashUnion
- Tins::IfPredicate
- Tins::InstanceExec
- Tins::Interpreter
- Tins::Limited
- Tins::LinesFile
- Tins::LinesFile::LineExtension
- Tins::Memoize
- Tins::Memoize::CacheMethods
- Tins::MethodDescription
- Tins::MethodMissingDelegator
- Tins::MethodMissingDelegator::DelegatorClass
- Tins::MethodMissingDelegator::DelegatorModule
- Tins::Minimize
- Tins::ModuleGroup
- Tins::NamedSet
- Tins::Null
- Tins::Null::Kernel
- Tins::NullClass
- Tins::NullPlus
- Tins::Once
- Tins::P
- Tins::ParameterizedModule
- Tins::PartialApplication
- Tins::ProcCompose
- Tins::ProcPrelude
- Tins::RangePlus
- Tins::RequireMaybe
- Tins::Responding
- Tins::Rotate
- Tins::Scope
- Tins::SecureWrite
- Tins::SexySingleton
- Tins::SexySingleton::SingletonClassMethods
- Tins::Shuffle
- Tins::StringByteOrderMark
- Tins::StringCamelize
- Tins::StringUnderscore
- Tins::StringVersion
- Tins::StringVersion::Version
- Tins::Subhash
- Tins::SymbolMaker
- Tins::Terminal
- Tins::ThreadGlobal
- Tins::ThreadLocal
- Tins::TimeDummy
- Tins::TimeFreezer
- Tins::To
- Tins::ToProc
- Tins::Token
- Tins::UniqBy
- Tins::Write
- Object
- Object::DSLKit
- Object::Spruz
- Array
- Date
- DateTime
- Enumerable
- File
- Hash
- IO
- IRB
- Method
- Module
- Proc
- Range
- String
- Symbol
- Time
- UnboundMethod

No matching classes.

# Tins::StringVersion::Version

### Public Class Methods

new(string) click to toggle source

    # File lib/tins/string_version.rb, line 6
    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/tins/string_version.rb, line 65
    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/tins/string_version.rb, line 72
    def ==(other)
      (self <=> other).zero?
    end

[](index) click to toggle source

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

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

    # File lib/tins/string_version.rb, line 47
    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/tins/string_version.rb, line 76
    def array
      @version.split('.').map { |x| x.to_i }
    end

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

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

build=(number) click to toggle source

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

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

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

major=(number) click to toggle source

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

minor() click to toggle source

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

minor=(number) click to toggle source

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

pred!() click to toggle source

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

revision() click to toggle source

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

revision=(number) click to toggle source

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

succ!() click to toggle source

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

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

    # File lib/tins/string_version.rb, line 82
    def to_s
      @version
    end

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

    # File lib/tins/string_version.rb, line 88
    def version
      self
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.