Module: Melai::StringHelpers

Defined in:
lib/melai/string_helpers.rb

Overview

This module provides some string helper methods

Instance Method Summary collapse

Instance Method Details

#get_arch_from_filename(filename) ⇒ String

Find the arch name within a filename

Returns:

  • (String)

    the arch name



12
13
14
15
16
17
18
19
# File 'lib/melai/string_helpers.rb', line 12

def get_arch_from_filename(filename)
  case
  when matched = filename.match(/(i686|x86_64|i386|amd64)/)
    arch = matched[0]
  else
    return 'unknown'
  end
end

#get_unstable_from_filename(filename) ⇒ Object

TODO: needs work, currently unused



35
36
37
38
# File 'lib/melai/string_helpers.rb', line 35

def get_unstable_from_filename(filename)
  unstable = /unstable/.match(filename)
  return unstable
end

#get_version_from_filename(filename) ⇒ Object, String

Find the version within a filename

Returns:

  • (Object)

    the version object, Versionomy-style

  • (String)

    The Major + Minor versions



26
27
28
29
30
31
32
# File 'lib/melai/string_helpers.rb', line 26

def get_version_from_filename(filename)
  version = Versionomy.parse(/(\d+)\.(\d+)\.(\d+)/.match(filename).to_s)
  # TODO: If we start packaging prerelease/rc packages, try:
  # (\d+)\.(\d+)\.(\d+)(?:-[^\.]+)?
  dist = [version.major, version.minor].join(".")
  return version, dist
end