Skip to content

Commit

Permalink
initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
William Weckl committed Feb 13, 2015
0 parents commit 49d1725
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.gem
.bundle
.rvmrc
Gemfile.lock
pkg/*
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "http://rubygems.org"

gemspec
22 changes: 22 additions & 0 deletions MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2015 William Weckl

MIT License

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.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# NIS Faker

Gerador de NIS (PIS / PASEP / NIT).

Generates Brazilian NIS (PIS / PASEP / NIT) numbers.

## Install

Use rubygems:

gem install nis_faker

Or add it to your Gemfile

group :development, :test do
# ...
gem 'nis_faker'
end

## Usage

Faker::Nis.number #=> "12073822829"
Faker::Nis.pretty #=> "120.7382.282-9"

## License

NIS Faker is released under the MIT license
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "bundler/gem_tasks"
64 changes: 64 additions & 0 deletions lib/faker/nis.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
module Faker
class Nis
class << self
def number
generate_numbers

@numbers.join
end

def pretty
generate_numbers

new_numbers_array = []
@numbers.each_with_index do |number, index|
new_numbers_array << '.' if index == 3 || index == 8
new_numbers_array << '-' if index == 10
new_numbers_array << number
end

new_numbers_array.join
end

private

def generate_numbers
@numbers = []
10.times do
@numbers << Random.new.rand(1..9)
end

last_digit = (11 - (sum_products % 11))
last_digit = 0 if last_digit > 9
@numbers << last_digit

generate_numbers if black_list.include?(@numbers.join)

@numbers
end

def multiply_weights
@x = []
i = 0
[3, 2, 9, 8, 7, 6, 5, 4, 3, 2].each do |weight|
@x << @numbers[i] * weight
i += 1
end
end

def sum_products
multiply_weights
sum = 0
10.times do |n|
sum += @x[n]
end
sum
end

def black_list
%w(000.0000.000-0)
end

end
end
end
1 change: 1 addition & 0 deletions lib/nis_faker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'faker/nis'
17 changes: 17 additions & 0 deletions nis_faker.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = "nis_faker"
s.version = "0.0.1"
s.platform = Gem::Platform::RUBY
s.authors = ["William Weckl"]
s.email = ["[email protected]"]
s.homepage = "https://github.com/williamweckl/nis_faker"
s.summary = %q{Generate fake brazilian pis/pasep/nit numbers}

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_development_dependency 'rake', '>= 0.8.7'
end

0 comments on commit 49d1725

Please sign in to comment.