rvr 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +26 -0
- data/lib/rvr.rb +34 -0
- data/spec/rvr_spec.rb +51 -0
- data/spec/spec_helper.rb +1 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 944027f324c281b9c477e12f63c08c3d651c6237
|
4
|
+
data.tar.gz: 3898c46558de9889ef2d15acbdd553526549028f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e235f90ca5ca3e385da21c7429df79eef15a52eb15a243f8015f9dbf2e81949f7cb92b538a2d79573938981a8f014b8000b1878618454a473428335f67f7cb87
|
7
|
+
data.tar.gz: dbbc6eb066fe76813689ca4a70ca477a30c32aadfb7f416faa929c6a833b4cea344608ac6356a9a49b8eb3e6240858617c9569153df6993684c165ee7852f8bd
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Rvr'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
Bundler::GemHelper.install_tasks
|
21
|
+
|
22
|
+
require 'rspec/core/rake_task'
|
23
|
+
|
24
|
+
RSpec::Core::RakeTask.new('spec')
|
25
|
+
|
26
|
+
task default: :spec
|
data/lib/rvr.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "active_model"
|
2
|
+
|
3
|
+
class Rvr
|
4
|
+
include ActiveModel::Validations
|
5
|
+
|
6
|
+
attr_accessor :regon
|
7
|
+
|
8
|
+
validates :regon, presence: true, numericality: true, length: { is: 9 }
|
9
|
+
validate :checksum
|
10
|
+
|
11
|
+
def initialize(value)
|
12
|
+
self.regon = value
|
13
|
+
end
|
14
|
+
|
15
|
+
def regon=(value)
|
16
|
+
@regon = value.to_s.delete(" ").delete("-")
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def checksum
|
21
|
+
errors.add(:regon) unless control_number == regon[8].to_i
|
22
|
+
end
|
23
|
+
|
24
|
+
def control_number
|
25
|
+
s = 0
|
26
|
+
(0..7).each { |i| s += (regon[i].to_i*control_array[i]) }
|
27
|
+
s % 11 == 10 ? 0 : s % 11
|
28
|
+
end
|
29
|
+
|
30
|
+
def control_array
|
31
|
+
[8, 9, 2, 3, 4, 5, 6, 7]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
data/spec/rvr_spec.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rvr do
|
4
|
+
describe "via validations" do
|
5
|
+
it "should verify presence of regon" do
|
6
|
+
@nvr = Rvr.new(nil)
|
7
|
+
@nvr.should_not be_valid
|
8
|
+
end
|
9
|
+
|
10
|
+
context "should verify length of regon" do
|
11
|
+
it { Rvr.new("12345").should_not be_valid }
|
12
|
+
|
13
|
+
it { Rvr.new("1234567890").should_not be_valid }
|
14
|
+
end
|
15
|
+
|
16
|
+
context "should verify numericality of regon" do
|
17
|
+
it { Rvr.new("abcdefghij").should_not be_valid }
|
18
|
+
|
19
|
+
it { Rvr.new("12345678a0").should_not be_valid }
|
20
|
+
end
|
21
|
+
|
22
|
+
it "regon always should be a string" do
|
23
|
+
@nvr = Rvr.new(1234567890)
|
24
|
+
@nvr.regon.should eq("1234567890")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should remove all spaces from regon" do
|
28
|
+
@nvr = Rvr.new("123 45 67 890")
|
29
|
+
@nvr.regon.should eq("1234567890")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should remove all dashes from regon" do
|
33
|
+
@nvr = Rvr.new("123-45-67-890")
|
34
|
+
@nvr.regon.should eq("1234567890")
|
35
|
+
end
|
36
|
+
|
37
|
+
context "checksum" do
|
38
|
+
it "shouldn't accept incorrect regon number" do
|
39
|
+
Rvr.new("1234567890").should_not be_valid
|
40
|
+
end
|
41
|
+
|
42
|
+
context "should accept correct regon numbers" do
|
43
|
+
it { Rvr.new("472836141").should be_valid }
|
44
|
+
|
45
|
+
it { Rvr.new("000515780").should be_valid }
|
46
|
+
|
47
|
+
it { Rvr.new("14-00-92-077").should be_valid }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "rvr"
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rvr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Szymon Rut
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activemodel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: debugger
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- rut.szymon@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/rvr.rb
|
63
|
+
- MIT-LICENSE
|
64
|
+
- Rakefile
|
65
|
+
- README.rdoc
|
66
|
+
- spec/spec_helper.rb
|
67
|
+
- spec/rvr_spec.rb
|
68
|
+
homepage: https://github.com/RutSzymon/rvr
|
69
|
+
licenses: []
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.0.5
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: REGON validator
|
91
|
+
test_files:
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
- spec/rvr_spec.rb
|