Skip to content

Commit

Permalink
Ajoute la méthode Acronomyze comme helper pour être utilisé sur la pa…
Browse files Browse the repository at this point in the history
…ge toutes les démarches
  • Loading branch information
kara22 committed Jun 3, 2024
1 parent 27f15bb commit 8e093e8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module ApplicationHelper
APP_HOST = ENV['APP_HOST']
APP_HOST_LEGACY = ENV['APP_HOST_LEGACY']
REGEXP_REPLACE_TRAILING_EXTENSION = /(\.\w+)+$/.freeze
REGEXP_REPLACE_WORD_SEPARATOR = /[\s_-]+/.freeze

def app_host_legacy?(request)
return false if APP_HOST_LEGACY.blank?
Expand Down Expand Up @@ -145,4 +147,11 @@ def dsfr_icon(classes, *options)
tag.span(class: class_names(classes, 'fr-icon--sm': sm, 'fr-mr-1v': mr),
"aria-hidden" => true)
end

def acronymize(str)
str.gsub(REGEXP_REPLACE_TRAILING_EXTENSION, '')

Check warning on line 152 in app/helpers/application_helper.rb

View check run for this annotation

Codecov / codecov/patch

app/helpers/application_helper.rb#L152

Added line #L152 was not covered by tests
.split(REGEXP_REPLACE_WORD_SEPARATOR)
.map { |word| word[0].upcase }

Check warning on line 154 in app/helpers/application_helper.rb

View check run for this annotation

Codecov / codecov/patch

app/helpers/application_helper.rb#L154

Added line #L154 was not covered by tests
.join
end
end
25 changes: 25 additions & 0 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,29 @@
it { is_expected.to eq("") }
end
end
describe '#acronymize' do
it 'returns the acronym of a given string' do
expect(helper.acronymize('Application Name')).to eq('AN')
expect(helper.acronymize('Hello World')).to eq('HW')
expect(helper.acronymize('Demarches Simplifiees')).to eq('DS')
end

it 'handles single word input' do
expect(helper.acronymize('Word')).to eq('W')
end

it 'returns an empty string for empty input' do
expect(helper.acronymize('')).to eq('')
end

it 'handles strings with extensions' do
expect(helper.acronymize('file_name.txt')).to eq('FN')
expect(helper.acronymize('example.pdf')).to eq('E')
end

it 'handles strings with various word separators' do
expect(helper.acronymize('multi-word_string')).to eq('MWS')
expect(helper.acronymize('another_example-test')).to eq('AET')
end
end
end

0 comments on commit 8e093e8

Please sign in to comment.