Class: Faussaire::Ancien
- Inherits:
-
Object
- Object
- Faussaire::Ancien
- Defined in:
- lib/faussaire/ancien.rb
Constant Summary collapse
- DATA_PATH =
File.('../../../locale/fr.yml', __FILE__)
Class Method Summary collapse
-
.creature ⇒ String
Produces a random mythical creature name.
-
.fetch(key) ⇒ Object?
Fetches and samples data based on the provided key.
-
.historic_figure ⇒ String
Produces a random historic figure name.
-
.words ⇒ String
Retrieves a random word.
Class Method Details
.creature ⇒ String
Produces a random mythical creature name.
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.
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_figure ⇒ String
Produces a random historic figure name.
40 41 42 |
# File 'lib/faussaire/ancien.rb', line 40 def self.historic_figure fetch('fr.faussaire.ancien.historic_figure') end |
.words ⇒ String
Retrieves a random word.
52 53 54 |
# File 'lib/faussaire/ancien.rb', line 52 def self.words fetch('fr.faussaire.ancien.words') end |