Sha256: 041e732c5528bf7680b8b6731e06620ee51042ba0153d1ca8b3dab7d81f9d584

Contents?: true

Size: 1.37 KB

Versions: 7

Compression:

Stored size: 1.37 KB

Contents

#
module Brcobranca
  # Métodos auxiliares de formatação de strings
  module FormatacaoString
    # 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
    #
    def format_size(size)
      if self.size > size
        remove_accents.strip.gsub(/\s+/, ' ').gsub(/[^A-Za-z0-9[[:space:]]]/, '').truncate(size)
      else
        remove_accents.strip.gsub(/\s+/, ' ').gsub(/[^A-Za-z0-9[[:space:]]]/, '').ljust(size, ' ')
      end
    end

    def truncate(truncate_at)
      return dup unless length > truncate_at
      "#{self[0, truncate_at]}"
    end

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

  end
end

[String].each do |klass|
  klass.class_eval { include Brcobranca::FormatacaoString }
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
brcobranca-9.2.2 lib/brcobranca/formatacao_string.rb
brcobranca-9.2.1 lib/brcobranca/formatacao_string.rb
brcobranca-9.2.0 lib/brcobranca/formatacao_string.rb
brcobranca-9.1.2 lib/brcobranca/formatacao_string.rb
brcobranca-9.1.1 lib/brcobranca/formatacao_string.rb
brcobranca-9.1.0 lib/brcobranca/formatacao_string.rb
brcobranca-9.0.0 lib/brcobranca/formatacao_string.rb