Method: Elus::Piece.convert_code
- Defined in:
- lib/elus/piece.rb
.convert_code(input) ⇒ Object
Pre-processes string into valid code for Piece creation
24 25 26 27 28 29 30 31 |
# File 'lib/elus/piece.rb', line 24 def Piece.convert_code(input) # Remove all invalid chars from input and transcode it into sort chars input_code = input.downcase.gsub(INVALID, '').tr(VALID, SORT) # Remove dupes and sort unless code contains digits or special chars (place-dependent) input_code = input_code.scan(/\w/).uniq.sort.reverse.join unless input_code =~ /[01!=.]/ # Translate sort chars into final chars input_code.tr!(SORT, FINAL) if input_code =~ PATTERN end |