Class: LetsCert::Runner::ValidTime

Inherits:
Object
  • Object
show all
Defined in:
lib/letscert/runner/valid_time.rb

Overview

Class used to process validation time from String.

Author:

  • Sylvain Daubert

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ ValidTime

Returns a new instance of ValidTime.

Parameters:

  • str (String)

    time string. May be:

    • an integer -> time in seconds

    • an integer plus a letter:

      • 30m: 30 minutes,

      • 30h: 30 hours,

      • 30d: 30 days.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/letscert/runner/valid_time.rb', line 35

def initialize(str)
  m = str.match(/^(\d+)([mhd])?$/)
  if m
    @seconds = case m[2]
               when nil
                 m[1].to_i
               when 'm'
                 m[1].to_i * 60
               when 'h'
                 m[1].to_i * 60 * 60
               when 'd'
                 m[1].to_i * 24 * 60 * 60
               end
  else
    raise OptionParser::InvalidArgument,
          "invalid argument: --valid-min #{str}"
  end
  @string = str
end

Instance Method Details

#to_sString

Get time as string

Returns:

  • (String)


63
64
65
# File 'lib/letscert/runner/valid_time.rb', line 63

def to_s
  @string
end

#to_secondsInteger

Get time in seconds

Returns:

  • (Integer)


57
58
59
# File 'lib/letscert/runner/valid_time.rb', line 57

def to_seconds
  @seconds
end