Module: Tins::StringVersion

Defined in:
lib/tins/string_version.rb

Overview

Provides version string parsing and comparison functionality.

This module allows working with semantic version strings in a more intuitive way, supporting operations like comparison, incrementing, and accessing individual components.

Examples:

Basic usage

version = "1.2.3".version
puts version.major # => 1
puts version.minor # => 2
puts version.build # => 3

Comparison operations

v1 = "1.2.3".version
v2 = "1.2.4".version
puts v1 < v2       # => true
puts v1 == v2      # => false

Version manipulation

version = "1.2.3".version
version.bump(:minor) # => "1.3.0"
version.succ!        # increments last component

Defined Under Namespace

Classes: Version

Constant Summary collapse

LEVELS =

Map of version level symbols to their numeric indices

[ :major, :minor, :build, :revision ].each_with_index.
each_with_object({}) { |(k, v), h| h[k] = v }.freeze
SYMBOLS =

Inverted map of LEVELS for symbol lookup

LEVELS.invert.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.compare(version1, operator, version2) ⇒ Boolean

Compares two version strings using the specified operator

Parameters:

  • version1 (String)

    First version string

  • operator (Symbol)

    Comparison operator (:<, :<=, :==, :>=, :>)

  • version2 (String)

    Second version string

Returns:

  • (Boolean)

    Result of the comparison



269
270
271
# File 'lib/tins/string_version.rb', line 269

def self.compare(version1, operator, version2)
  Version.new(version1).send(operator, Version.new(version2))
end

Instance Method Details

#versionTins::StringVersion::Version

Creates a Version object from this string

Returns:



259
260
261
# File 'lib/tins/string_version.rb', line 259

def version
  Version.new(self)
end