Module: Timewizard::Utils::Wizardry

Defined in:
lib/timewizard/utils/wizardry.rb

Overview

Contains utility functions in a cleverly named module.

Author:

  • Richard Harrah

Since:

  • 0.2.4

Constant Summary collapse

VERSION_REGEX =

Since:

  • 0.2.4

/((\d+\.)?(\d+\.)?(\*|\d+))(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?/

Class Method Summary collapse

Class Method Details

.only_version(stringy) ⇒ String

Returns a substring of the passed-in value that matches the version regex.

Parameters:

  • stringy (String)

    string from which to extract version string

Returns:

Raises:

  • (ArgumentError)

    if stringy is null

Since:

  • 0.2.4



16
17
18
19
20
21
# File 'lib/timewizard/utils/wizardry.rb', line 16

def self.only_version(stringy)
  if stringy.nil?
    raise ArgumentError, "stringy cannot be null"
  end
  VERSION_REGEX.match(stringy.to_s).to_s
end