class SearchYJ::UniqueLogger
Logging unique data
@author [indeep-xyz]
Public Class Methods
new(limit)
click to toggle source
Initialize myself. @param limit [Integer] The limit of the log
# File lib/searchyj/unique_logger.rb, line 10 def initialize(limit) @limit = limit reset end
Public Instance Methods
add(value)
click to toggle source
Add to log. If can not add the value, count up the adding failure. @param value [type] [description]
@return [Object]
False if could not add the value.
# File lib/searchyj/unique_logger.rb, line 21 def add(value) if exist?(value) @failure_count += 1 return false end @log << value @log.shift if @log.length > @limit end
exist?(value)
click to toggle source
Check whether the value is in @log @param value [Object]
@return [Boolean]
True if the argument found. False else.
# File lib/searchyj/unique_logger.rb, line 65 def exist?(value) @log.include?(value) end
failure_count(with_reset = false)
click to toggle source
Return the number of the failure count. @param with_reset [Boolean] If true, reset failure count
@return [Integer] The number of failure count
# File lib/searchyj/unique_logger.rb, line 47 def failure_count(with_reset = false) n = @failure_count reset_failure_count if with_reset n end
length()
click to toggle source
Return the size of log. @return [Integer] The size of @log
# File lib/searchyj/unique_logger.rb, line 33 def length @log.length end
reset()
click to toggle source
Reset my own log data.
# File lib/searchyj/unique_logger.rb, line 38 def reset @log = [] reset_failure_count end
reset_failure_count()
click to toggle source
Reset the failure count.
# File lib/searchyj/unique_logger.rb, line 55 def reset_failure_count @failure_count = 0 end