class LittleWeasel::Configuration
This class encapsulates the configuration properties for this gem and provides methods and attributes that allow for management of the same.
attr_reader :max_dictionary_file_megabytes, :max_invalid_words_bytesize, :metadata_observers
Attributes
Public Class Methods
The constructor; calls {#reset}.
# File lib/LittleWeasel/configure.rb, line 30 def initialize reset end
Public Instance Methods
Returns the maximum consumable dictionary size in bytes. Dictionaries larger than {#max_dictionary_file_bytes} will raise an error.
The default is 5 megabytes.
@return [Integer] the maximum number of bytes for a dictionary.
# File lib/LittleWeasel/configure.rb, line 56 def max_dictionary_file_bytes @max_dictionary_file_megabytes * 1_000_000 end
rubocop: disable Style/TrivialAccessors
# File lib/LittleWeasel/configure.rb, line 69 def max_dictionary_file_megabytes=(value) @max_dictionary_file_megabytes = value end
Sets the maximum cache size (in bytes) for invalid words. If less than or equal to 0, invalid words will NOT be cached.
If greater than 0, invalid words will be cached up to and including {#max_invalid_words_bytesize} bytes.
@see max_invalid_words_bytesize?
# File lib/LittleWeasel/configure.rb, line 80 def max_invalid_words_bytesize=(value) value = 0 if value.negative? @max_invalid_words_bytesize = value end
If {#max_invalid_words_bytesize} is > 0, true will be returned; false otherwise.
@return [true, false] based on {#max_invalid_words_bytesize}.
# File lib/LittleWeasel/configure.rb, line 64 def max_invalid_words_bytesize? max_invalid_words_bytesize.positive? end
# File lib/LittleWeasel/configure.rb, line 85 def metadata_observers=(value) raise ArgumentError, "Argument value is not an Array: #{value.class}" unless value.is_a? Array # TODO: Limit the amount of observer classes, exploits? @metadata_observers = value end
Resets the configuration settings to their default values.
@return [void]
# File lib/LittleWeasel/configure.rb, line 37 def reset @max_dictionary_file_megabytes = 5 @max_invalid_words_bytesize = 25_000 @metadata_observers = [ LittleWeasel::Metadata::InvalidWordsMetadata ] # TODO: Is this the correct regex to use, or is there something better? # @word_block_regex = /\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/ # @word_block_regex = /(?:(?:[\-A-Za-z0-9]|\d(?!\d|\b))+(?:'[\-A-Za-z0-9]+)?)/ # @word_block_regex = /(?:(?:[\-a-z0-9]|\d(?!\d|\b))+(?:'[\-a-z0-9]+)?)/i @word_block_regex = /[[[:word:]]'-]+/ end
# File lib/LittleWeasel/configure.rb, line 93 def word_block_regex=(value) @word_block_regex = value end