Class: Crazipsum::Registry

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/crazipsum/registry.rb

Overview

Registry is a singleton class that registers and stores different dictionnary types.

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



14
15
16
# File 'lib/crazipsum/registry.rb', line 14

def initialize
  @registry = {}
end

Instance Method Details

#[](type) ⇒ Dictionnary?

Retrieves a dictionnary given its type.

Parameters:

  • type (String, Symbol)

    the name of the dictionnary to retrieve

Returns:

  • (Dictionnary, nil)

    the dictionnary registered for this name. nil if no dictionnary was registered for this type.



32
33
34
# File 'lib/crazipsum/registry.rb', line 32

def [](type)
  registry[type.to_s]
end

#register(type, words, fillers: []) ⇒ Object

Registers a new type of Dictionnary that can later be retrieved with #[].

Parameters:

  • type (String, Symbol)

    a name for that dictionnary. This type will be used later when calling ‘Crazipsum(type)`.

  • words (Array<String>)

    a list of words used when generating the lorem ipsum.

  • fillers (Array<String>, false) (defaults to: [])

    a list of words used to fill in the sentences when generating the lorem ipsum.



24
25
26
# File 'lib/crazipsum/registry.rb', line 24

def register(type, words, fillers: [])
  registry[type.to_s] = Dictionnary.new(words, fillers: fillers)
end