Module: Brcobranca::FormatacaoString

Defined in:
lib/brcobranca/formatacao_string.rb

Overview

Métodos auxiliares de formatação de strings

Instance Method Summary collapse

Instance Method Details

#format_size(size) ⇒ Object

Formata o tamanho da string para o tamanho passado se a string for menor, adiciona espacos a direita se a string for maior, trunca para o num. de caracteres



11
12
13
14
15
16
17
18
# File 'lib/brcobranca/formatacao_string.rb', line 11

def format_size(size)
  clean_str = remove_accents.strip.gsub(/\s+/, ' ').gsub(/[^A-Za-z0-9[[:space:]]]/, '')
  if clean_str.size > size
    clean_str.truncate(size)
  else
    clean_str.ljust(size, ' ')
  end
end

#remove_accentsObject



26
27
28
29
30
31
# File 'lib/brcobranca/formatacao_string.rb', line 26

def remove_accents
  tr(
    'ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž',
    'AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz'
  )
end

#truncate(truncate_at) ⇒ Object



20
21
22
23
24
# File 'lib/brcobranca/formatacao_string.rb', line 20

def truncate(truncate_at)
  return dup unless length > truncate_at

  (self[0, truncate_at]).to_s
end