Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
51 lines (43 sloc) 1.03 KB
# encoding: UTF-8
$:.unshift File.dirname(__FILE__)
# Gems requires
require 'rubygems'
require 'sinatra'
require 'haml'
require 'faker'
# App requires
require 'lib/helpers'
require 'lib/entity'
require 'lib/person'
require 'lib/company'
require 'lib/document'
require 'lib/cnpj'
require 'lib/cpf'
Faker::Config.locale = "pt-br"
# Set utf-8 for all the outgoing content
before do
headers "Content-Type" => "text/html; charset=utf-8"
end
get '/' do
@companies = []
@persons = []
5.times do
@companies << Company.new
@persons << Person.new
end
haml :index
end
post '/validate' do
if params[:document].empty?
@result = {:status => :notice, :message => "Informe o CPF ou CNPJ."}
else
@result = if Cpf.new(params[:document]).valid?
{:status => :success, :message => "CPF Válido."}
elsif Cnpj.new(params[:document]).valid?
{:status => :success, :message => "CNPJ Válido."}
else
{:status => :error, :message => "Documento inválido."}
end
end
haml :validate, :layout => false
end