class LittleWeasel::Services::InvalidWordsService
This class calculates the total amount of bytes cached invalid words take up in the given dictionary and returns the results. In addition to this, metadata is also compiled to determine how many more bytes of invalid word data can be cached before the cache is depleted and shutdown.
Attributes
current_bytesize[RW]
dictionary[RW]
Public Class Methods
new(dictionary)
click to toggle source
# File lib/LittleWeasel/services/invalid_words_service.rb, line 12 def initialize(dictionary) self.dictionary = dictionary self.current_bytesize = 0 end
Public Instance Methods
execute()
click to toggle source
# File lib/LittleWeasel/services/invalid_words_service.rb, line 17 def execute return build_return unless max_invalid_words_bytesize? self.current_bytesize = calculate_current_bytesize build_return end
Private Instance Methods
build_return()
click to toggle source
# File lib/LittleWeasel/services/invalid_words_service.rb, line 38 def build_return Metadata::InvalidWordsServiceResults.new( max_invalid_words_bytesize_on: max_invalid_words_bytesize?, current_invalid_word_bytesize: current_bytesize, max_invalid_words_bytesize: max_invalid_words_bytesize ) end
calculate_current_bytesize()
click to toggle source
# File lib/LittleWeasel/services/invalid_words_service.rb, line 28 def calculate_current_bytesize dictionary.reduce(0) do |bytesize, word_and_found| unless word_and_found.last bytesize += word_and_found.first.bytesize break unless bytesize < max_invalid_words_bytesize end bytesize end end
config()
click to toggle source
# File lib/LittleWeasel/services/invalid_words_service.rb, line 54 def config @config ||= LittleWeasel.configuration end
max_invalid_words_bytesize()
click to toggle source
# File lib/LittleWeasel/services/invalid_words_service.rb, line 46 def max_invalid_words_bytesize @max_invalid_words_bytesize ||= config.max_invalid_words_bytesize end
max_invalid_words_bytesize?()
click to toggle source
# File lib/LittleWeasel/services/invalid_words_service.rb, line 50 def max_invalid_words_bytesize? config.max_invalid_words_bytesize? end