Skip to content

Instantly share code, notes, and snippets.

@mAlishera
Last active August 29, 2015 14:24
Show Gist options
  • Save mAlishera/4da5eb3e5f94d8b98547 to your computer and use it in GitHub Desktop.
Save mAlishera/4da5eb3e5f94d8b98547 to your computer and use it in GitHub Desktop.
input_maska_spec.rb
def maskarad(input, maska)
input = input.to_s.chars
maska.gsub(/@/) do |at|
input.shift
end.gsub(/^-*/, '').gsub(/-*$/, '') + input.join
end
=begin Input data
Маска | Номер | Результат
------------------------------------------
@@@ | 5432 | 5432
@-@@ | 5432 | 5-432
@-@@ | @432 | @-432
РОС@@-@@-@@@ | 5432 | РОС54-32
РОС@@-@@-@@@ | 42 | РОС42
@-@@-TAIL | 5432 | 5-43-TAIL2
@-@@-@@@@@@@@@-TAIL | 5432 | 5-43-2-TAIL
=end
describe 'Maska' do
it 'input 5432 apply mask @@@ and get result 5432' do
expect(maskarad('5432', '@@@')).to eql('5432')
end
it 'input 5432 apply mask @-@@ and get result 5-432' do
expect(maskarad('5432', '@-@@')).to eql('5-432')
end
it 'input @432 apply mask @-@@ and get result @-432' do
expect(maskarad('@432', '@-@@')).to eql('@-432')
end
it 'input 5432 apply mask РОС@@-@@-@@@ and get result РОС54-32' do
expect(maskarad('5432', 'РОС@@-@@-@@@')).to eql('РОС54-32')
end
it 'input 42 apply mask РОС@@-@@-@@@ and get result РОС42' do
expect(maskarad('42', 'РОС@@-@@-@@@')).to eql('РОС42')
end
it 'input 5432 apply mask @-@@-TAIL and get result 5-43-TAIL2' do
expect(maskarad('5432', '@-@@-TAIL')).to eql('5-43-TAIL2')
end
it 'input 5432 apply mask @-@@-@@@@@@@@@-TAIL and get result 5-43-2-TAIL' do
expect(maskarad('5432', '@-@@-@@@@@@@@@-TAIL')).to eql('5-43-2-TAIL')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment