unpack brazilian-rails

This commit is contained in:
2013-07-14 11:09:25 -04:00
parent 7d287fe530
commit e563725dc5
131 changed files with 5496 additions and 0 deletions

View File

View File

@@ -0,0 +1,20 @@
Copyright (c) 2008 [name of plugin creator]
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1 @@
Aqui vai o README

View File

@@ -0,0 +1,71 @@
# encoding: UTF-8
require "rubygems"
require "rake"
require "rake/testtask"
require "rdoc/task"
require "rake/packagetask"
require "rake/gempackagetask"
require File.join(File.dirname(__FILE__), "lib", "brstring", "version")
PKG_BUILD = ENV["PKG_BUILD"] ? "." + ENV["PKG_BUILD"] : ""
PKG_NAME = "brstring"
PKG_VERSION = BrString::VERSION::STRING + PKG_BUILD
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
desc "Default Task"
task :default => [ :test ]
# Run the unit tests
Rake::TestTask.new { |t|
t.libs << "test"
t.pattern = "test/*_test.rb"
t.verbose = true
t.warning = false
}
#Generate the RDoc documentation
Rake::RDocTask.new { |rdoc|
rdoc.rdoc_dir = "doc"
rdoc.title = "Brazilian Rails -- String"
rdoc.options << "--line-numbers" << "--inline-source" << "-A cattr_accessor=object"
rdoc.options << "--charset" << "utf-8"
rdoc.template = "#{ENV["template"]}.rb" if ENV["template"]
rdoc.rdoc_files.include("README", "CHANGELOG")
rdoc.rdoc_files.include("lib/**/*")
}
# Create compressed packages
spec = Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = PKG_NAME
s.summary = "brstring é uma das gems que compoem o Brazilian Rails"
s.description = %q{brstring é uma das gems que compoem o Brazilian Rails}
s.version = PKG_VERSION
s.authors = ["Marcos Tapajós", "Celestino Gomes", "Andre Kupkosvki", "Vinícius Teles", "Felipe Barreto", "Rafael Walter", "Cassio Marques"]
s.email = %w"tapajos@gmail.com tinorj@gmail.com kupkovski@gmail.com vinicius.m.teles@gmail.com felipebarreto@gmail.com rafawalter@gmail.com cassiommc@gmail.com"
s.rubyforge_project = "brstring"
s.homepage = "http://www.improveit.com.br/software_livre/brazilian_rails"
s.add_dependency("activesupport", ">= 3.0.0")
s.add_development_dependency "rake"
s.has_rdoc = true
s.requirements << "none"
s.require_path = "lib"
s.files = [ "Rakefile", "README", "CHANGELOG", "MIT-LICENSE" ]
s.files = s.files + Dir.glob( "lib/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
s.files = s.files + Dir.glob( "test/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
end
Rake::GemPackageTask.new(spec) do |p|
p.gem_spec = spec
end
desc "Publish the release files to RubyForge."
task :release => [ :package ] do
`gem push pkg/#{PKG_FILE_NAME}.gem`
end

View File

@@ -0,0 +1,14 @@
$:.unshift(File.dirname(__FILE__)) unless
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
$KCODE = 'utf-8' if RUBY_VERSION < '1.9'
require 'rubygems'
require 'active_support'
require 'active_support/core_ext'
%w(version
string_portuguese).each {|req| require File.dirname(__FILE__) + "/brstring/#{req}"}
module BrString
end

View File

@@ -0,0 +1,154 @@
# encoding: UTF-8
class String
MINUSCULAS_COM_ACENTO = 'áéíóúâêîôûàèìòùäëïöüãõñç'
MAIUSCULAS_COM_ACENTO = 'ÁÉÍÓÚÂÊÎÔÛÀÈÌÒÙÄËÏÖÜÃÕÑÇ'
MINUSCULAS = "abcdefghijklmnopqrstuvwxyz#{MINUSCULAS_COM_ACENTO}"
MAIUSCULAS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ#{MAIUSCULAS_COM_ACENTO}"
# Normaliza nomes proprios
#
# Exemplo:
# String.nome_proprio('maria de souza dos santos e silva da costa') ==> 'Maria de Souza dos Santos e Silva da Costa'
def self.nome_proprio(texto)
return texto if texto.blank?
self.titleize(texto).gsub(/ D(a|e|o|as|os) /, ' d\1 ').gsub(/ E /, ' e ')
end
# Normaliza nomes proprios
#
# Exemplo:
# 'maria de souza dos santos e silva da costa'.nome_proprio ==> 'Maria de Souza dos Santos e Silva da Costa'
def nome_proprio
String.nome_proprio(self)
end
# Normaliza nomes proprios na própria instância.
#
# Exemplo:
# texto = 'maria de souza dos santos e silva da costa'
# texto.nome_proprio!
# texto ==> 'Maria de Souza dos Santos e Silva da Costa'
def nome_proprio!
self.gsub!(/^.*$/, String.nome_proprio(self)) if self
end
# Remove as letras acentuadas
#
# Exemplo:
# String.remover_acentos('texto está com acentuação') ==> 'texto esta com acentuacao'
def self.remover_acentos(texto)
return texto if texto.blank?
texto = texto.gsub(/(á|à|ã|â|ä)/, 'a').gsub(/(é|è|ê|ë)/, 'e').gsub(/(í|ì|î|ï)/, 'i').gsub(/(ó|ò|õ|ô|ö)/, 'o').gsub(/(ú|ù|û|ü)/, 'u')
texto = texto.gsub(/(Á|À|Ã|Â|Ä)/, 'A').gsub(/(É|È|Ê|Ë)/, 'E').gsub(/(Í|Ì|Î|Ï)/, 'I').gsub(/(Ó|Ò|Õ|Ô|Ö)/, 'O').gsub(/(Ú|Ù|Û|Ü)/, 'U')
texto = texto.gsub(/ñ/, 'n').gsub(/Ñ/, 'N')
texto = texto.gsub(/ç/, 'c').gsub(/Ç/, 'C')
texto
end
# Remove as letras acentuadas
#
# Exemplo:
# 'texto está com acentuação'.remover_acentos ==> 'texto esta com acentuacao'
def remover_acentos
String.remover_acentos(self)
end
# Remove as letras acentuadas na própria instância.
#
# Exemplo:
# texto = 'texto está com acentuação'
# texto.remover_acentos!
# texto ==> 'texto esta com acentuacao'
def remover_acentos!
self.gsub!(/^.*$/, String.remover_acentos(self)) if self
end
# Retorna uma string com caracteres maiusculos
#
# Exemplo:
# String.upcase('texto com acentuação' ==> 'TEXTO COM ACENTUAÇÃO'
def self.upcase(texto)
return texto if texto.nil? or texto.empty?
texto.tr(MINUSCULAS, MAIUSCULAS)
end
# Retorna uma string com caracteres maiusculos
#
# Exemplo:
# 'texto com acentuação'.upcase ==> 'TEXTO COM ACENTUAÇÃO'
def upcase
String.upcase(self)
end
# Converte para caracteres maiusculos na própria instância
#
# Exemplo:
# texto = 'texto com acentuação'
# texto.upcase
# texto ==> 'TEXTO COM ACENTUAÇÃO'
def upcase!
self.gsub!(/^.*$/, String.upcase(self)) if self
end
# Retorna uma string com caracteres minúsculos
#
# Exemplo:
# String.downcase('TEXTO COM ACENTUAÇÃO') ==> 'texto com acentuação'
def self.downcase(texto)
return texto if texto.nil? or texto.empty?
texto.tr(MAIUSCULAS, MINUSCULAS)
end
# Retorna uma string com caracteres minúsculos
#
# Exemplo:
# 'TEXTO COM ACENTUAÇÃO'.downcase ==> 'texto com acentuação'
def downcase
String.downcase(self)
end
# Converte para caracteres minúsculos na própria instância
#
# Exemplo:
# texto = 'TEXTO COM ACENTUAÇÃO'
# texto.downcase
# texto ==> 'texto com acentuação'
def downcase!
self.gsub!(/^.*$/, String.downcase(self)) if self
end
# Passa a primeira letra de cada palavra para maiúscula e as demais para minúsculas.
#
# Exemplo:
# String.titleize('o livro esta sobre a mesa!') ==> 'O Livro Esta Sobre A Mesa!'
def self.titleize(texto)
return texto if texto.nil? or texto.empty?
texto = texto.downcase
texto = texto.downcase
texto.mb_chars[0] = texto.mb_chars.first.upcase
texto = texto.gsub(/\s[a-z#{String::MINUSCULAS_COM_ACENTO}]/) {|a| a.upcase }
texto
end
# Passa a primeira letra de cada palavra para maiúscula e as demais para minúsculas.
#
# Exemplo:
# 'o livro esta sobre a mesa!'.titleize ==> 'O Livro Esta Sobre A Mesa!'
def titleize
String.titleize(self)
end
# Passa a primeira letra de cada palavra para maiúscula e as demais para minúsculas na própria instância.
#
# Exemplo:
# texto = 'o livro esta sobre a mesa!'
# texto.titleize!
# texto ==> 'O Livro Esta Sobre A Mesa!'
def titleize!
self.gsub!(/^.*$/, String.titleize(self)) if self
end
end

View File

@@ -0,0 +1,10 @@
module BrString
module VERSION #:nodoc:
MAJOR = 3
MINOR = 3
TINY = 0
STRING = "#{MAJOR}.#{MINOR}.#{TINY}"
end
end

View File

@@ -0,0 +1 @@
require File.dirname(__FILE__) + '/../lib/brstring'

View File

@@ -0,0 +1,164 @@
# encoding: UTF-8
require File.dirname(__FILE__) + '/test_helper'
NOMES_PROPRIOS = {
'Paulo Gomes' => 'paulo gomes',
'Pedro da Silva' => 'pedro da silva',
'Jonas de Souza' => 'jonas de souza',
'Maria do Carmo' => 'maria do carmo',
'Silva e Souza' => 'silva e souza',
'Jardim das Oliveiras' => 'jardim das oliveiras',
'José dos Santos' => 'josé dos santos',
'Tomé Gomes da Silva de Souza' => 'tomé gomes da silva de souza',
'Maria do Carmo e Souza das Couves dos Santos' => 'maria do carmo e souza das couves dos santos',
'Átila da Silva' => 'átila da silva',
'Érica da Silva' => 'érica da silva',
'Íris Santos' => 'íris santos',
'Paulo dos Santos' => 'paulo dos saNTos',
' José da Silva ' => ' josé da silva ',
'' => ''
} #:nodoc:
NOMES_TITLEIZE = {
'José Silva' => 'josé silva',
'José Silva' => 'JOSÉ SILVA',
'José Da Silva' => 'josé da silva',
' José Da Silva ' => ' josé da silva ',
'Átila Da Silva' => 'átila da silva',
"Á É Í Ó Ú À È Ì Ò Ù Ã Õ Â Ê Î Ô Û Ä Ë Ï Ö Ü" => 'á é í ó ú à è ì ò ù ã õ â ê î ô û ä ë ï ö ü'
} #:nodoc:
class StringPortugueseTest < Test::Unit::TestCase
def test_letras_maiusculas
assert_equal 'ABCDEFGHIJKLMNOPQRSTUVWXYZÁÉÍÓÚÂÊÎÔÛÀÈÌÒÙÄËÏÖÜÃÕÑÇ', String::MAIUSCULAS
end
def test_letras_minusculas
assert_equal 'abcdefghijklmnopqrstuvwxyzáéíóúâêîôûàèìòùäëïöüãõñç', String::MINUSCULAS
end
def test_string_nome_proprio
NOMES_PROPRIOS.each {|key, value| assert_equal key, String.nome_proprio(value) }
palavras_excluidas = %w(? ! @ # $ % & * \ / ? , . ; ] [ } { = + 0 1 2 3 4 5 6 7 8 9)
palavras_excluidas.each do |char|
assert_equal char, String.nome_proprio(char), "Não deveria alterar o caracter '#{char}'"
end
assert_nil String.nome_proprio(nil)
end
def test_nome_proprio
NOMES_PROPRIOS.each {|key, value| assert_equal key, value.nome_proprio }
palavras_excluidas = %w(? ! @ # $ % & * \ / ? , . ; ] [ } { = + 0 1 2 3 4 5 6 7 8 9)
palavras_excluidas.each do |char|
assert_equal char, char.nome_proprio, "Não deveria alterar o caracter '#{char}'"
end
end
def test_nome_proprio!
NOMES_PROPRIOS.each do |key, value|
nome = value
nome.nome_proprio!
assert_equal key, nome
end
palavras_excluidas = %w(? ! @ # $ % & * \ / ? , . ; ] [ } { = + 0 1 2 3 4 5 6 7 8 9)
palavras_excluidas.each do |char|
nome = char.clone
nome.nome_proprio!
assert_equal char, nome, "Não deveria alterar o caracter '#{char}'"
end
end
def test_string_remover_acentos
assert_equal 'aeiouAEIOU', String.remover_acentos("áéíóúÁÉÍÓÚ")
assert_equal 'aeiouAEIOU', String.remover_acentos("âêîôûÂÊÎÔÛ")
assert_equal 'aeiouAEIOU', String.remover_acentos("àèìòùÀÈÌÒÙ")
assert_equal 'aeiouAEIOU', String.remover_acentos("äëïöüÄËÏÖÜ")
assert_equal 'aoAO', String.remover_acentos("ãõÃÕ")
assert_equal 'nN', String.remover_acentos("ñÑ")
assert_equal 'cC', String.remover_acentos("çÇ")
assert_equal 'aeiouAEIOUaeiouAEIOUaeiouAEIOUaeiouAEIOUaoAOnNcC', String.remover_acentos("áéíóúÁÉÍÓÚâêîôûÂÊÎÔÛàèìòùÀÈÌÒÙäëïöüÄËÏÖÜãõÃÕñÑçÇ")
assert_nil String.remover_acentos(nil)
end
def test_remover_acentos
assert_equal 'aeiouAEIOU', "áéíóúÁÉÍÓÚ".remover_acentos
assert_equal 'aeiouAEIOU', "âêîôûÂÊÎÔÛ".remover_acentos
assert_equal 'aeiouAEIOU', "àèìòùÀÈÌÒÙ".remover_acentos
assert_equal 'aeiouAEIOU', "äëïöüÄËÏÖÜ".remover_acentos
assert_equal 'aoAO', "ãõÃÕ".remover_acentos
assert_equal 'nN', "ñÑ".remover_acentos
assert_equal 'cC', "çÇ".remover_acentos
assert_equal 'aeiouAEIOUaeiouAEIOUaeiouAEIOUaeiouAEIOUaoAOnNcC', "áéíóúÁÉÍÓÚâêîôûÂÊÎÔÛàèìòùÀÈÌÒÙäëïöüÄËÏÖÜãõÃÕñÑçÇ".remover_acentos
end
def test_remover_acentos!
string = 'áéíóúÁÉÍÓÚ'
string.remover_acentos!
assert_equal 'aeiouAEIOU', string
end
def test_nao_trocar_caracter_pipe_pelo_caracter_a_ao_removere_acentos
assert_equal '|', String.remover_acentos('|')
assert_not_equal 'a', String.remover_acentos('|')
assert_equal '|', '|'.remover_acentos
assert_not_equal 'a', '|'.remover_acentos
char_pipe = '|'
char_pipe.remover_acentos!
assert_equal '|', char_pipe
assert_not_equal 'a', char_pipe
end
def test_string_downcase
assert_equal String::MINUSCULAS, String.downcase(String::MAIUSCULAS)
assert_nil String.downcase(nil)
end
def test_downcase
assert_equal String::MINUSCULAS, String::MAIUSCULAS.downcase
end
def test_downcase!
string = String::MAIUSCULAS.clone
string.downcase!
assert_equal String::MINUSCULAS, string
end
def test_string_upcase
assert_equal String::MAIUSCULAS, String.upcase(String::MINUSCULAS)
assert_nil String.upcase(nil)
end
def test_upcase
assert_equal String::MAIUSCULAS, String::MINUSCULAS.upcase
end
def test_upcase!
string = String::MINUSCULAS.clone
string.upcase!
assert_equal String::MAIUSCULAS, string
end
def test_string_titleize
NOMES_TITLEIZE.each {|k,v| assert_equal k, String.titleize(v) }
assert_nil String.titleize(nil)
end
def test_titleize
NOMES_TITLEIZE.each {|k,v| assert_equal k, v.titleize }
end
def test_titleize!
NOMES_TITLEIZE.each do |k,v|
v.titleize!
assert_equal k, v
end
end
end

View File

@@ -0,0 +1,15 @@
require 'test/unit'
require File.dirname(__FILE__) + '/../lib/brstring'
def tornar_metodos_publicos(clazz)
clazz.class_eval do
private_instance_methods.each { |instance_method| public instance_method }
private_methods.each { |method| public_class_method method }
end
end
def p80 text
p '*'*80
p text
yield if block_given?
end