Class: Faussaire::Music

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

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.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/music.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

.houseString

Produces a random house song.

Examples:

Faussaire::Music.house #=> "House is a feeling - LA Riots"

Returns:

  • (String)


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

def self.house
  fetch('fr.faussaire.music.house')
end

.rapString

Produces a random French rap song.

Examples:

Faussaire::Music.rap #=> "Onizuka - PNL"

Returns:

  • (String)


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

def self.rap
  fetch('fr.faussaire.music.rap')
end

.varieteString

Produces a random French variété song.

Examples:

Faussaire::Music.variete #=> "Laisse tomber les filles - France Gall"

Returns:

  • (String)


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

def self.variete
  fetch('fr.faussaire.music.variete')
end