Skip to content
Ruby Semantic Version class
Branch: master
Clone or download
jlindsey Merge pull request #34 from pvdb/fix_typo_in_readme
Fix small typo in README examples

thanks @pvdb!
Latest commit 54de37b Apr 21, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib Merge pull request #33 from jleeothon/master Feb 14, 2018
spec Merge pull request #33 from jleeothon/master Feb 14, 2018
.gitignore Remove and ignore Gemfile.lock; bad form to keep it in the repo Oct 2, 2013
.rspec Initi RSpec Jul 23, 2012
.travis.yml Added more rvm versions to .travis.yml Feb 2, 2018
Gemfile Switch away from outdated :rubygems Gemfile source Aug 16, 2013
LICENSE Add MIT License Jul 23, 2012
README.md keep original alignment Apr 13, 2018
Rakefile Switch to RSpec Jul 23, 2012
semantic.gemspec

README.md

Semantic

BuildStatus

A small Ruby utility class to aid in the storage, parsing, and comparison of SemVer-style Version strings.

See the SemVer site for more details.

Usage

This library exposes a single class – Semantic::Version. Simply pass in a valid SemVer string to the initializer.

require 'semantic'

version = Semantic::Version.new '1.6.5'
version.major             # => 1
version.minor             # => 6
version.patch             # => 5

newer_version = Semantic::Version.new '1.7.0'
version > newer_version   # => false
newer_version <=> version # => 1

complex_version = Semantic::Version.new '3.7.9-pre.1+revision.15723'
complex_version.pre       # => "pre.1"
complex_version.build     # => "revision.15623"

# semantic supports Pessimistic Operator
version.satisfies? '~> 1.5'    # => true
version.satisfies? '~> 1.6.0'  # => true

# incrementing version numbers
version = Semantic::Version.new('0.1.0')
new_version = version.increment!(:major)    # 1.1.0
new_version = version.increment!(:minor)    # 0.2.0
new_version = version.increment!(:patch)    # 0.1.1

new_version = version.major!                # 1.1.0
new_version = version.minor!                # 0.2.0
new_version = version.patch!                # 0.1.1
# (note: increment! & friends return a copy and leave the original unchanged)

There is also a set of core extensions as an optional require:

require 'semantic'
require 'semantic/core_ext'

"1.8.7-pre.123".to_version

License

Copyright (c) 2012 Josh Lindsey. See LICENSE for details.

You can’t perform that action at this time.