Class: Faussaire::Ancien

Inherits:
Object
  • Object
show all
Defined in:
lib/faussaire/ancien.rb

Constant Summary collapse

DATA_PATH =
File.expand_path('../../../locale/fr.yml', __FILE__)

Class Method Summary collapse

Class Method Details

.creatureString

Produces a random mythical creature name.

Examples:

Faussaire::Ancien.creature #=> "Dragon"

Returns:

  • (String)


28
29
30
# File 'lib/faussaire/ancien.rb', line 28

def self.creature
  fetch('fr.faussaire.ancien.creature')
end

.fetch(key) ⇒ Object?

Fetches and samples data based on the provided key. If the fetched data is an array, it samples a single item, otherwise returns the data directly.

Parameters:

  • key (String)

    The dot-separated key used to access the data.

Returns:

  • (Object, nil)

    The data fetched and optionally sampled.



14
15
16
17
18
# File 'lib/faussaire/ancien.rb', line 14

def self.fetch(key)
  data = YAML.load_file(DATA_PATH)
  result = data.dig(*key.split('.'))
  result.is_a?(Array) ? result.sample : result
end

.historic_figureString

Produces a random historic figure name.

Examples:

Faussaire::Ancien.historic_figure #=> "Napoléon Bonaparte"

Returns:

  • (String)


40
41
42
# File 'lib/faussaire/ancien.rb', line 40

def self.historic_figure
  fetch('fr.faussaire.ancien.historic_figure')
end

.wordsString

Retrieves a random word.

Examples:

Faussaire::Ancien.words #=> "torteleresse"

Returns:

  • (String)


52
53
54
# File 'lib/faussaire/ancien.rb', line 52

def self.words
  fetch('fr.faussaire.ancien.words')
end