Sha256: 2155bf01b5edd2dc669f43c3238a7039dac8834b02bc15650919ca55935b7599
Contents?: true
Size: 1019 Bytes
Versions: 2
Compression:
Stored size: 1019 Bytes
Contents
# frozen_string_literal: true module God module Conditions class Tries < PollCondition attr_accessor :times, :within def prepare @timeline = Timeline.new(times) end def reset @timeline.clear end def valid? valid = true valid &= complain("Attribute 'times' must be specified", self) if times.nil? valid end def test @timeline << Time.now consensus = (@timeline.size == times) duration = within.nil? || (@timeline.last - @timeline.first) < within history = if within "[#{@timeline.size}/#{times} within #{(@timeline.last - @timeline.first).to_i}s]" else "[#{@timeline.size}/#{times}]" end if consensus && duration self.info = "tries exceeded #{history}" true else self.info = "tries within bounds #{history}" false end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
resurrected_god-1.1.1 | lib/god/conditions/tries.rb |
resurrected_god-1.1.0 | lib/god/conditions/tries.rb |