mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 09:42:46 +08:00
Merge pull request #1127 from ZmagoD/zd_SCI_2307_v3
Adds custom method that generates smart annotations name for repository
This commit is contained in:
commit
8a92f1a499
2 changed files with 43 additions and 7 deletions
|
@ -56,7 +56,15 @@ module SmartAnnotations
|
||||||
end
|
end
|
||||||
|
|
||||||
def trim_repository_name(name)
|
def trim_repository_name(name)
|
||||||
name.strip.slice(0..2).capitalize
|
splited_name = name.split
|
||||||
|
size = splited_name.size
|
||||||
|
return name.strip.slice(0..2).capitalize if size == 1
|
||||||
|
generate_name_from_array(splited_name, size).capitalize
|
||||||
|
end
|
||||||
|
|
||||||
|
def generate_name_from_array(names, size)
|
||||||
|
return "#{names[0].slice(0..1)}#{names[1][0]}" if size == 2
|
||||||
|
"#{names[0][0]}#{names[1][0]}#{names[2][0]}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -52,12 +52,40 @@ describe SmartAnnotations::HtmlPreview do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#trim_repository_name/1' do
|
context '#trim_repository_name/1' do
|
||||||
it 'is returns a 3 letter upcase string' do
|
describe 'repository name with one word' do
|
||||||
trimmed_repository_name = subject.__send__(
|
it 'is returns a 3 letter capitalize string' do
|
||||||
:trim_repository_name, 'banana'
|
trimmed_repository_name = subject.__send__(
|
||||||
)
|
:trim_repository_name, 'banana'
|
||||||
expect(trimmed_repository_name).to eq('Ban')
|
)
|
||||||
|
expect(trimmed_repository_name).to eq('Ban')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'repository name with two words' do
|
||||||
|
it 'returns the first two letters of first word ' \
|
||||||
|
'and the first letter of second word' do
|
||||||
|
trimmed_repository_name = subject.__send__(
|
||||||
|
:trim_repository_name, 'two words'
|
||||||
|
)
|
||||||
|
expect(trimmed_repository_name).to eq('Tww')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not return 3 letters of the first word' do
|
||||||
|
trimmed_repository_name = subject.__send__(
|
||||||
|
:trim_repository_name, 'two words'
|
||||||
|
)
|
||||||
|
expect(trimmed_repository_name).not_to eq('Two')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'repository name with three words' do
|
||||||
|
it 'returns the first letter of first 3 words capitalized' do
|
||||||
|
trimmed_repository_name = subject.__send__(
|
||||||
|
:trim_repository_name, 'two words of wisdom'
|
||||||
|
)
|
||||||
|
expect(trimmed_repository_name).to eq('Two')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue