-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
base of status in piraterie module set - pending data
- Loading branch information
Showing
3 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'yaml' | ||
|
||
module Faussaire | ||
class Piraterie | ||
DATA_PATH = File.expand_path('../../../locale/fr.yml', __FILE__) | ||
|
||
## | ||
# 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. | ||
# | ||
# @param key [String] The dot-separated key used to access the data. | ||
# @return [Object, nil] The data fetched and optionally sampled. | ||
# | ||
def self.fetch(key) | ||
data = YAML.load_file(DATA_PATH) | ||
result = data.dig(*key.split('.')) | ||
result.is_a?(Array) ? result.sample : result | ||
end | ||
|
||
## | ||
# Produces a random pirate-themed position. | ||
# | ||
# @return [String] | ||
# | ||
# @example | ||
# Faussaire::Piraterie.role #=> "Moussaillon" | ||
# | ||
def self.role | ||
fetch('fr.faussaire.piraterie.role') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'spec_helper' | ||
require 'yaml' | ||
require 'faussaire/piraterie' | ||
|
||
RSpec.describe Faussaire::Music do | ||
before(:all) do | ||
@data = YAML.load_file(File.expand_path('../locale/fr.yml', __dir__)) | ||
end | ||
|
||
describe '.no duplicate values' do | ||
context 'in roles list' do | ||
it 'does not contain duplicates' do | ||
roles = @data.dig('fr', 'faussaire', 'piraterie', 'role') | ||
unique_roles = roles.uniq | ||
|
||
duplicates = roles.group_by { |role| role }.select { |_, v| v.size > 1 }.keys | ||
|
||
expect(duplicates).to be_empty, "Duplicates found in piraterie roles: #{duplicates.join(', ')}" | ||
end | ||
end | ||
end | ||
end |