orgnummer 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8df60f0387f4b8eddc8b1ac31c373d8ba6169c38
4
- data.tar.gz: b56cd3117a802d90620e4ef9febe5f472934639c
3
+ metadata.gz: f24e4c6f558b205f87b2f75102161433debd4dd7
4
+ data.tar.gz: cef2128bd1e69997d1cb96c8cbcd0ece0cfa5a95
5
5
  SHA512:
6
- metadata.gz: 92a44d30b9cf9bfbaaf5917dcbceb748202eecab7742ec988017c4d5df7f4d75794b61e7a9ab63e6b8cf7c45867cb0adb3551a617fa10672a5507e600c566067
7
- data.tar.gz: ad3026e329ab54e01b70996875f55d23fa96989b453c5777e8d248c1471ae41752dcc7ca17a41bf5c84aa1d9ac1bc89493ec1e1a10d3f9fbd141a03a10b289b4
6
+ metadata.gz: 64c8493276abf2f7755d4067c0ce69271bd331e31da53186aac021077fb4407841268c5d304752aa31b780e18f0a9cc44095eb4bebe74b1821469e2b64f9646f
7
+ data.tar.gz: b2f246028cd559b0aa7996b11bc4b10a1c7fd6004c15a38e7d55077a46c6dff226a589b39ceff6de3f0cfbff8dad1bdcacc1a1b687b3098b40653ca658f27cee
data/README.md CHANGED
@@ -17,6 +17,8 @@ Or install it yourself as:
17
17
  $ gem install orgnummer
18
18
 
19
19
  ## Changelog
20
+ 0.1.1. Added implementation of eql? and hash
21
+
20
22
  0.1.0. Added support for resolving swedish organization types
21
23
 
22
24
  0.0.1. Initial version
@@ -27,12 +29,16 @@ Or install it yourself as:
27
29
 
28
30
  ```ruby
29
31
  bolag = Orgnummer.new(5568610827)
32
+ # bolag = Orgnummer.new('5568610827') is valid
33
+ # bolag = Orgnummer.new('556861-0827') is valid
34
+ # bolag = Orgnummer.new('55') is valid but bolag.valid? will be false
30
35
 
31
36
  if bolag.valid?
32
37
  #do something
33
38
 
34
39
  if bolag.type_of_organization eq :aktiebolag
35
40
  #do something
41
+
36
42
  ```
37
43
 
38
44
  ## Contributing
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ begin
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ rescue LoadError
6
+ end
@@ -5,16 +5,18 @@ class Orgnummer
5
5
 
6
6
  def initialize(number)
7
7
  @number = number.to_s
8
+ if !@number.nil? && !@number.empty?
9
+ # hyphen is ok, but remove it to pass validation algorithm
10
+ @number = @number.gsub(/-/, '')
11
+ # strip, we are kind and helpful
12
+ @number = @number.strip
13
+ end
8
14
  end
9
15
 
10
16
  def valid?
11
17
  valid = false
12
18
 
13
19
  if !@number.nil? && !@number.empty?
14
- # hyphen is ok, but remove it to pass validation algorithm
15
- @number = @number.gsub(/-/, '')
16
- # strip, we are kind and helpful
17
- @number = @number.strip
18
20
 
19
21
  if (@number =~/\A\d{10}\z/) == 0
20
22
  multiplier = 2
@@ -42,6 +44,17 @@ class Orgnummer
42
44
  valid? ? get_type_from_first_char : :odefinierat
43
45
  end
44
46
 
47
+ def eql?(orgnummer)
48
+ self.class.equal?(orgnummer.class) &&
49
+ number == orgnummer.number
50
+ end
51
+
52
+ alias == eql?
53
+
54
+ def hash
55
+ number.hash
56
+ end
57
+
45
58
  private
46
59
 
47
60
  def get_type_from_first_char
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'orgnummer'
7
- spec.version = '0.1.0'
7
+ spec.version = '0.2.0'
8
8
  spec.authors = ['Jonas']
9
9
  spec.email = ['jonas.lundstrom@mirendo.se']
10
10
  spec.description = %q{Create and validate format of the swedish organisationsnummer}
@@ -18,6 +18,7 @@ describe Orgnummer do
18
18
  let(:bad_end) { Orgnummer.new(5568610828) }
19
19
 
20
20
  let(:ab) { Orgnummer.new(5568610827) }
21
+ let(:ba) { Orgnummer.new(5568610828) }
21
22
  let(:ab_s) { Orgnummer.new('5568610827') }
22
23
  let(:ab_s_with_hyphen) { Orgnummer.new('556861-0827') }
23
24
  let(:ab_s_with_spaces) { Orgnummer.new(' 556861-0827 ') }
@@ -50,6 +51,25 @@ describe Orgnummer do
50
51
  end
51
52
  end
52
53
 
54
+ describe 'equals and hash code' do
55
+ it 'behaves as expected for equals and variants' do
56
+ expect(ab).to eq ab
57
+ expect(ab).to eql ab
58
+ expect(ab).to equal ab
59
+ expect(ab).to_not equal ab_s
60
+ expect(ab).to eq ab_s
61
+ expect(ab_s).to eq ab
62
+ expect(ab_s).to_not eq ba
63
+
64
+ end
65
+
66
+ it 'behaves as expected for hash code' do
67
+ expect(ab.hash).to eq ab.hash
68
+ expect(ab.hash).to equal ab_s.hash
69
+ expect(ab.hash).to_not eq ba.hash
70
+ end
71
+ end
72
+
53
73
  describe 'type of organization' do
54
74
  it 'resolves type of organization based on number' do
55
75
  expect(ab.type_of_organization).to eq :aktiebolag
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orgnummer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-24 00:00:00.000000000 Z
11
+ date: 2015-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler