class EnvironmentInformation::Queries::ComplexVersion

Public Class Methods

new( for_this_program = nil, run_already = true ) { || ... } click to toggle source
#

initialize

The first argument is mandatory.

#
# File lib/environment_information/queries/complex_version.rb, line 25
def initialize(
    for_this_program = nil,
    run_already      = true
  )
  reset
  set_program_name(
    for_this_program
  )
  # ======================================================================= #
  # === Handle blocks given next
  # ======================================================================= #
  if block_given?
    yielded = yield
    if yielded.is_a? Hash
      if yielded.has_key? :prefix_to_use
        @prefix_to_use << yielded.delete(:prefix_to_use)
      end
    end
  end
  run if run_already
end

Public Instance Methods

program_name?() click to toggle source
#

program_name?

#
# File lib/environment_information/queries/complex_version.rb, line 75
def program_name?
  @program_name
end
program_version?() click to toggle source
#

program_version?

#
# File lib/environment_information/queries/complex_version.rb, line 82
def program_version?
  @program_version
end
Also aliased as: version?
reset() click to toggle source
#

reset

#
# File lib/environment_information/queries/complex_version.rb, line 50
def reset
  # ======================================================================= #
  # === @program_name
  # ======================================================================= #
  @program_name    = ''.dup
  # ======================================================================= #
  # === @program_version
  # ======================================================================= #
  @program_version = nil
  # ======================================================================= #
  # === @prefix_to_use
  # ======================================================================= #
  @prefix_to_use = ''.dup
end
return_version_of( this_program = @program_name ) click to toggle source
#

return_version_of

#
# File lib/environment_information/queries/complex_version.rb, line 89
def return_version_of(
    this_program = @program_name
  )
  _ = ::EnvironmentInformation.query_to_use_for_the_individual_components?
  if _.nil?
    _ = ::EnvironmentInformation.load_file_query_to_use_for_the_individual_components
  end
  if _.has_key?(this_program)
    cmd_to_run = _[this_program]
    case cmd_to_run
    # ===================================================================== #
    # === :custom_busybox
    # ===================================================================== #
    when :custom_busybox
      @program_version = ::EnvironmentInformation.return_version_of_busybox
    # ===================================================================== #
    # === :custom_xrandr
    # ===================================================================== #
    when :custom_xrandr
      @program_version = ::EnvironmentInformation.return_version_of_xrandr
    # ===================================================================== #
    # === :custom_xvid
    # ===================================================================== #
    when :custom_xvid
      @program_version = ::EnvironmentInformation.return_version_of_xvid
    # ===================================================================== #
    # === :custom_boost
    # ===================================================================== #
    when :custom_boost
      @program_version = ::EnvironmentInformation.return_version_of_boost
    # ===================================================================== #
    # === :custom_mpc
    # ===================================================================== #
    when :custom_mpc
      @program_version = ::EnvironmentInformation.return_version_of_mpc
    else
      result = `#{@prefix_to_use}#{cmd_to_run} #{ERROR_LINE}`.to_s.strip.dup
      if result.include? ' #' # Handle "uname -a" aka Linux darkstar.example.net 5.4.50 #1 SMP
        result = result.split(' #').first.strip 
      end
      @program_version = result
    end
    return nil if @program_version.nil?
    if @program_version.include? '# HMMER ' # <- Specifically for "hammer".
      @program_version = @program_version.scan(
        /# HMMER (\d{0,2}\.\d{0,2}\.\d{0,2})/
      ).flatten.first.to_s
    end
    if @program_version.include? 'extracts blocks from damag' # bzip2recover
      @program_version = @program_version.scan(
        /bzip2recover (\d{0,2}\.\d{0,2}\.\d{0,2}): extracts blocks from damaged .bz2 files/
      ).flatten.first.to_s.dup
    end
    # ===================================================================== #
    # === Handle Imagemagick: 'Version: ImageMagick 7.0.10-28'
    # ===================================================================== #
    if @program_version.include? 'Version: ImageMagick '
      @program_version = @program_version.scan(
        /Version: ImageMagick (\d{0,2}\.\d{0,2}\.\d{0,2}-\d{0,2})/
      ).flatten.first.to_s.tr('-','.')
    end
    # ===================================================================== #
    # === Handle 'KDE Frameworks: 5.73.0'
    # ===================================================================== #
    if @program_version.include? 'KDE Frameworks: '
      @program_version = @program_version.scan(
        /KDE Frameworks: (\d{0,2}\.\d{0,2}\.\d{0,2})/
      ).flatten.first.to_s
    end
    # ===================================================================== #
    # === Handle 'ncurses 6.2.20200212' aka ncurses
    # ===================================================================== #
    if @program_version.include? 'ncurses '
      @program_version = @program_version.scan(
        /ncurses (\d{1,1}\.\d{1,1})/
      ).flatten.first.to_s
    end
    # ===================================================================== #
    # === Handle ruby 'ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]'
    # ===================================================================== #
    if @program_version.include? 'ruby '
      @program_version = @program_version.scan(
        /^ruby (\d{1,1}\.\d{1,1}\.\d{1,1})/
      ).flatten.first.to_s
    end
    # ===================================================================== #
    # === Handle patchelf '0.12.20200827.8d3a16e'
    #
    # This can also include output such as "patchelf 0.14.3".
    # ===================================================================== #
    if @program_version.include? 'patchelf '
      @program_version = @program_version.scan(
        /^patchelf (\d{1,1}\.\d{1,2}\.?\d{0,2})/
      ).flatten.first.to_s
    end
    # ===================================================================== #
    # We have to be careful with the next, as a few programs report the
    # version on the second line, not on the first.
    # ===================================================================== #
    if @program_version.include? N
      @program_version = @program_version.split(N).first.strip
    end
    # ===================================================================== #
    # Next handle cases such as the following two examples:
    #
    #   "ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers"
    #   "openjdk version \"14.0.2\" 2020-07-14"
    #   "ffmpeg version n5.1.2 Copyright (c) 2000-2022 the FFmpeg developers"
    #
    # ===================================================================== #
    if @program_version.include? ' version '
      @program_version = @program_version.scan(
        / version n?"?(\d{0,2}\.\d{1,2}\.?\d{0,2})"?/ # See: See: https://rubular.com/r/39cIQqXin2oco0
      ).flatten.first.to_s.strip
    end
    # ===================================================================== #
    # Handle cases such as: "nginx/1.18.0"
    # ===================================================================== #
    if @program_version.include? '/'
      @program_version = @program_version.split('/').last.strip
    end
    if @program_version.include?('(') and # Specifically for XTERM.
       @program_version.include?(')')
      @program_version = @program_version.split('(').last.to_s.delete(')') # 7.7.0(359)
    end
    if @program_version.include? '-'
      # Specifically to fix relion: "3.1.0-commit-GITDIR"
      @program_version = @program_version.split('-').first.to_s.strip
    end
    if @program_version.include? COMMAND_NOT_FOUND
      @program_version = nil
    elsif @program_version.include? ' '
      # =================================================================== #
      # Assume input such as: "GNU ld (GNU Binutils) 2.35"
      # =================================================================== #
      @program_version = @program_version.split(' ').last
    end
  end
  return @program_version
end
run() click to toggle source
#

run

#
# File lib/environment_information/queries/complex_version.rb, line 233
def run
  return_version_of
end
set_program_name(i) click to toggle source
#

set_program_name

#
# File lib/environment_information/queries/complex_version.rb, line 68
def set_program_name(i)
  @program_name = i.to_sym if i
end
version?()
Alias for: program_version?