Module: Mixin::Guess

Included in:
Shell
Defined in:
lib/clearbooks/interface/thor/mixin/guess.rb

Instance Method Summary collapse

Instance Method Details

#guess_version(string) ⇒ Object

“rake, version 10.1.1”

-> 10.1.1

Examples:

e.g. “ruby 2.1.1p76 (2014-02-24 revision 45161) [i686-linux]”

-> 2.1.1


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/clearbooks/interface/thor/mixin/guess.rb', line 32

def guess_version string

  result      = ""

  begin

    # Sanity
    raise ArgumentError, "Version has to be of type string" unless( string.is_a?( String ) )
    raise ArgumentError, "Version can't be empty" if( string.empty? )

    result    = string.match( /\d+\.\d+\.\d+/ ).to_s # matches first only

  rescue Exception => e
    say "(EE) " + e.message, :red
    result    = ""
  end

  return result
end

#initialize(*args) ⇒ Object

Parameters:

  • args (Array)

    Argument array



20
21
22
# File 'lib/clearbooks/interface/thor/mixin/guess.rb', line 20

def initialize *args
  super
end