run-cl 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in run-cl.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 mespina
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Run::Cl
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'run-cl'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install run-cl
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile CHANGED
@@ -1,38 +1 @@
1
- #!/usr/bin/env rake
2
- begin
3
- require 'bundler/setup'
4
- rescue LoadError
5
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
- end
7
- begin
8
- require 'rdoc/task'
9
- rescue LoadError
10
- require 'rdoc/rdoc'
11
- require 'rake/rdoctask'
12
- RDoc::Task = Rake::RDocTask
13
- end
14
-
15
- RDoc::Task.new(:rdoc) do |rdoc|
16
- rdoc.rdoc_dir = 'rdoc'
17
- rdoc.title = 'Run'
18
- rdoc.options << '--line-numbers'
19
- rdoc.rdoc_files.include('README.rdoc')
20
- rdoc.rdoc_files.include('lib/**/*.rb')
21
- end
22
-
23
-
24
-
25
-
26
- Bundler::GemHelper.install_tasks
27
-
28
- require 'rake/testtask'
29
-
30
- Rake::TestTask.new(:test) do |t|
31
- t.libs << 'lib'
32
- t.libs << 'test'
33
- t.pattern = 'test/**/*_test.rb'
34
- t.verbose = false
35
- end
36
-
37
-
38
- task :default => :test
1
+ require "bundler/gem_tasks"
@@ -3,4 +3,5 @@ require 'run-cl/run_validator'
3
3
  require 'run-cl/version'
4
4
 
5
5
  module RunCl
6
+ # Your code goes here...
6
7
  end
@@ -1,3 +1,3 @@
1
1
  module RunCl
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'run-cl/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "run-cl"
8
+ gem.version = RunCl::VERSION
9
+ gem.authors = ["mespina"]
10
+ gem.email = ["mespina.icc@gmail.com"]
11
+ gem.summary = "Rut Chilenos"
12
+ gem.description = "Formateador/Desformateador, Generador, Validador de Rut Chilenos"
13
+ gem.homepage = "https://bitbucket.org/mespina/run"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
metadata CHANGED
@@ -1,73 +1,72 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: run-cl
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 1
9
+ version: 1.0.1
6
10
  platform: ruby
7
- authors:
11
+ authors:
8
12
  - mespina
9
13
  autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
- date: 2013-03-20 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: rails
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: 3.2.12
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: 3.2.12
16
+
17
+ date: 2013-03-19 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies: []
20
+
30
21
  description: Formateador/Desformateador, Generador, Validador de Rut Chilenos
31
- email:
22
+ email:
32
23
  - mespina.icc@gmail.com
33
24
  executables: []
25
+
34
26
  extensions: []
27
+
35
28
  extra_rdoc_files: []
36
- files:
37
- - config/locale/run-cl.en.yml
38
- - config/locale/run-cl.es-CL.yml
39
- - lib/run-cl/run.rb
40
- - lib/run-cl/run_validator.rb
41
- - lib/run-cl/version.rb
42
- - lib/run-cl.rb
43
- - lib/tasks/run_tasks.rake
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - LICENSE.txt
34
+ - README.md
44
35
  - Rakefile
45
- - test/run-cl_test.rb
46
- - test/test_helper.rb
36
+ - lib/run-cl.rb
37
+ - lib/run-cl/version.rb
38
+ - run-cl.gemspec
39
+ has_rdoc: true
47
40
  homepage: https://bitbucket.org/mespina/run
48
41
  licenses: []
42
+
49
43
  post_install_message:
50
44
  rdoc_options: []
51
- require_paths:
45
+
46
+ require_paths:
52
47
  - lib
53
- required_ruby_version: !ruby/object:Gem::Requirement
48
+ required_ruby_version: !ruby/object:Gem::Requirement
54
49
  none: false
55
- requirements:
56
- - - ! '>='
57
- - !ruby/object:Gem::Version
58
- version: '0'
59
- required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
57
  none: false
61
- requirements:
62
- - - ! '>='
63
- - !ruby/object:Gem::Version
64
- version: '0'
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ segments:
62
+ - 0
63
+ version: "0"
65
64
  requirements: []
65
+
66
66
  rubyforge_project:
67
- rubygems_version: 1.8.24
67
+ rubygems_version: 1.3.7
68
68
  signing_key:
69
69
  specification_version: 3
70
70
  summary: Rut Chilenos
71
- test_files:
72
- - test/run-cl_test.rb
73
- - test/test_helper.rb
71
+ test_files: []
72
+
@@ -1,3 +0,0 @@
1
- 'es-CL':
2
- run:
3
- invalid: Invalid
@@ -1,3 +0,0 @@
1
- 'es-CL':
2
- run:
3
- invalid: No es válido
@@ -1,86 +0,0 @@
1
- # module RunCl
2
- module Run
3
- extend self
4
-
5
- # Formatea un run
6
- def self.format run
7
- pos = 0
8
- run.reverse
9
- reverse = ""
10
- run.reverse.gsub("-", "").gsub(".", "").split('').each_with_index do |c, index|
11
- reverse += c
12
- if index == 0
13
- reverse += '-'
14
- elsif (pos == 3)
15
- reverse += "."
16
- pos = 0
17
- end
18
- pos += 1
19
- end
20
- reverse.reverse
21
- end
22
-
23
- # Quita el formato de un run
24
- def self.remove_format run
25
- run.gsub("-", "").gsub(".", "")
26
- end
27
-
28
- # Generar un run valido segun reglas chilenas y que ademas es unico para el modelo entregado
29
- def self.for model, attribute, randomize=true
30
- model_class = model.to_s.camelize.constantize
31
-
32
- valid_rut = randomize ? Run.generate : '111111111'
33
- while model_class.where(attribute.to_sym => valid_rut).any? do valid_rut = Run.generate end
34
- valid_rut
35
- end
36
-
37
- # Generar un run valido segun reglas chilenas
38
- def self.generate seed = nil
39
- run = (rand * 20000000).round + 5000000 unless seed.presence
40
-
41
- suma = 0
42
- mul = 2
43
- run.to_s.reverse.split('').each do |i|
44
- suma = suma + i.to_i * mul
45
- if mul == 7
46
- mul = 2
47
- else
48
- mul += 1
49
- end
50
- end
51
- res = suma % 11
52
-
53
- if res == 1
54
- return "#{run}k"
55
- elsif res == 0
56
- return "#{run}0"
57
- else
58
- return "#{run}#{11-res}"
59
- end
60
- end
61
-
62
- # Revisa si el run y digito entregado es valido
63
- def self.check_run run, digit
64
- return false if run.empty?
65
- return false if digit.empty?
66
-
67
- factor = 2
68
- suma = 0
69
- i = run.length - 1
70
-
71
- while i >= 0
72
- factor = 2 if factor > 7
73
- suma = suma + ( run[i] ).to_i * factor.to_i
74
- factor += 1
75
- i -= 1
76
- end
77
-
78
- dv = 11 - ( suma % 11 )
79
- dv = 0 if dv == 11
80
- dv = "k" if dv == 10
81
-
82
- return true if dv.to_s == digit.downcase
83
- false
84
- end
85
- end
86
- # end
@@ -1,22 +0,0 @@
1
- # encoding: utf-8
2
- # module RunCl
3
- class RunValidator < ActiveModel::Validator
4
- def validate record
5
- if record.respond_to? :run
6
- # record.errors[:run] << I18n.t('run.invalid') unless valid_run? record
7
- record.errors[:run] << 'no es válido' unless valid_run? record
8
- end
9
- end
10
-
11
- private
12
-
13
- def valid_run? record
14
- if run = record.run.presence
15
- record.run = ( run = run.match(/^(\d+)[^\d*](\d+)[^\d*](\d+)[^\d*](\d|k)|(\d+)[^\d*](\d|k)|(\d+k)|(\d+)$/i).to_s ) =~ /\.|\-/ ? run.gsub!(/\.|\-/, '') : run
16
- RunCl::Run.check_run record.run.chop, record.run.last
17
- else
18
- false
19
- end
20
- end
21
- end
22
- # end
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :run-cl do
3
- # # Task goes here
4
- # end
@@ -1,7 +0,0 @@
1
- require 'test_helper'
2
-
3
- class RunClTest < ActiveSupport::TestCase
4
- test "truth" do
5
- assert_kind_of Module, RunCl
6
- end
7
- end
@@ -1,15 +0,0 @@
1
- # Configure Rails Environment
2
- ENV["RAILS_ENV"] = "test"
3
-
4
- require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
- require "rails/test_help"
6
-
7
- Rails.backtrace_cleaner.remove_silencers!
8
-
9
- # Load support files
10
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
11
-
12
- # Load fixtures from the engine
13
- if ActiveSupport::TestCase.method_defined?(:fixture_path=)
14
- ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
15
- end