Skip to content

Commit

Permalink
base of status in piraterie module set - pending data
Browse files Browse the repository at this point in the history
  • Loading branch information
ikramagix committed Oct 26, 2024
1 parent b176732 commit 6a32a4a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
32 changes: 32 additions & 0 deletions lib/faussaire/piraterie.rb
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
4 changes: 3 additions & 1 deletion locale/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16615,4 +16615,6 @@ fr:
- "Capri c'est fini - Hervé Villard"
- "Belles belles belles - Claude François"
piraterie:
- "Pirate"
role:
- "Pirate"
- "Moussaillon"
22 changes: 22 additions & 0 deletions spec/piraterie_spec.rb
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

0 comments on commit 6a32a4a

Please sign in to comment.