Class: Drntest::SubscribeUntil

Inherits:
Directive show all
Defined in:
lib/drntest/directive.rb

Constant Summary collapse

DEFAULT_TIMEOUT_SECONDS =
1
ONE_MINUTE_IN_SECONDS =
60
ONE_HOUR_IN_SECONDS =
ONE_MINUTE_IN_SECONDS * 60

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameters) ⇒ SubscribeUntil

Returns a new instance of SubscribeUntil.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/drntest/directive.rb', line 79

def initialize(parameters)
  @max_messages = nil
  @timeout_seconds = nil

  parameters.each do |parameter|
    case parameter
    when /\A(\d+)(?:messages|msg)?\z/
      @max_messages = $1.to_i
    when /\A(\d+\.?|\.\d+|\d+\.\d+)s(?:ec(?:onds?)?)?\z/
      @timeout_seconds = $1.to_f
    when /\A(\d+\.?|\.\d+|\d+\.\d+)m(?:inutes?)?\z/
      @timeout_seconds = $1.to_f * ONE_MINUTE_IN_SECONDS
    when /\A(\d+\.?|\.\d+|\d+\.\d+)h(?:ours?)?\z/
      @timeout_seconds = $1.to_f * ONE_HOUR_IN_SECONDS
    end
  end

  if @max_messages.nil? and @timeout_seconds.nil?
    @timeout_seconds = DEFAULT_TIMEOUT_SECONDS
  end
end

Instance Attribute Details

#max_messagesObject (readonly)

Returns the value of attribute max_messages.



72
73
74
# File 'lib/drntest/directive.rb', line 72

def max_messages
  @max_messages
end

#timeout_secondsObject (readonly)

Returns the value of attribute timeout_seconds.



72
73
74
# File 'lib/drntest/directive.rb', line 72

def timeout_seconds
  @timeout_seconds
end