class Crazipsum::Registry
Registry
is a singleton class that registers and stores different dictionnary types.
Attributes
registry[R]
Public Class Methods
new()
click to toggle source
# File lib/crazipsum/registry.rb, line 14 def initialize @registry = {} end
Public Instance Methods
[](type)
click to toggle source
Retrieves a dictionnary given its type.
@param [String,Symbol] type the name of the dictionnary to retrieve @return [Dictionnary,nil] the dictionnary registered for this name. nil if no dictionnary was registered for this type.
# File lib/crazipsum/registry.rb, line 32 def [](type) registry[type.to_s] end
register(type, words, fillers: [])
click to toggle source
Registers a new type of Dictionnary
that can later be retrieved with []
.
@param [String,Symbol] type a name for that dictionnary. This type will be
used later when calling `Crazipsum(type)`.
@param [Array<String>] words a list of words used when generating the lorem ipsum. @param [Array<String>, false] fillers a list of words used to fill in the sentences when generating the lorem ipsum.
# File lib/crazipsum/registry.rb, line 24 def register(type, words, fillers: []) registry[type.to_s] = Dictionnary.new(words, fillers: fillers) end