Class: LittleWeasel::Services::InvalidWordsService
- Inherits:
-
Object
- Object
- LittleWeasel::Services::InvalidWordsService
- Defined in:
- lib/LittleWeasel/services/invalid_words_service.rb
Overview
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.
Instance Attribute Summary collapse
-
#current_bytesize ⇒ Object
private
Returns the value of attribute current_bytesize.
-
#dictionary ⇒ Object
private
Returns the value of attribute dictionary.
Instance Method Summary collapse
- #build_return ⇒ Object private
- #calculate_current_bytesize ⇒ Object private
- #config ⇒ Object private
- #execute ⇒ Object
-
#initialize(dictionary) ⇒ InvalidWordsService
constructor
A new instance of InvalidWordsService.
- #max_invalid_words_bytesize ⇒ Object private
- #max_invalid_words_bytesize? ⇒ Boolean private
Constructor Details
#initialize(dictionary) ⇒ InvalidWordsService
Returns a new instance of InvalidWordsService.
12 13 14 15 |
# File 'lib/LittleWeasel/services/invalid_words_service.rb', line 12 def initialize(dictionary) self.dictionary = dictionary self.current_bytesize = 0 end |
Instance Attribute Details
#current_bytesize ⇒ Object (private)
Returns the value of attribute current_bytesize.
26 27 28 |
# File 'lib/LittleWeasel/services/invalid_words_service.rb', line 26 def current_bytesize @current_bytesize end |
#dictionary ⇒ Object (private)
Returns the value of attribute dictionary.
26 27 28 |
# File 'lib/LittleWeasel/services/invalid_words_service.rb', line 26 def dictionary @dictionary end |
Instance Method Details
#build_return ⇒ Object (private)
38 39 40 41 42 43 44 |
# 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 ⇒ Object (private)
28 29 30 31 32 33 34 35 36 |
# 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 ⇒ Object (private)
54 55 56 |
# File 'lib/LittleWeasel/services/invalid_words_service.rb', line 54 def config @config ||= LittleWeasel.configuration end |
#execute ⇒ Object
17 18 19 20 21 22 |
# 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 |
#max_invalid_words_bytesize ⇒ Object (private)
46 47 48 |
# 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? ⇒ Boolean (private)
50 51 52 |
# File 'lib/LittleWeasel/services/invalid_words_service.rb', line 50 def max_invalid_words_bytesize? config.max_invalid_words_bytesize? end |