Skip to content

Commit

Permalink
🎉 bumps 0.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dgilperez committed Aug 21, 2020
1 parent 6131019 commit 050201e
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## 0.3.2

- Adds formatter for CA ~ @devthiago

## 0.3.1

- Removes forbidden combinations in the Netherlands ~ @gerard76
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_4.2.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
validates_zipcode (0.3.1)
validates_zipcode (0.3.2)
activemodel (>= 4.2.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_5.2.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
validates_zipcode (0.3.1)
validates_zipcode (0.3.2)
activemodel (>= 4.2.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_6.0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
validates_zipcode (0.3.1)
validates_zipcode (0.3.2)
activemodel (>= 4.2.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_edge.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ GIT
PATH
remote: ..
specs:
validates_zipcode (0.3.1)
validates_zipcode (0.3.2)
activemodel (>= 4.2.0)

GEM
Expand Down
11 changes: 5 additions & 6 deletions lib/validates_zipcode/formatter.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# frozen_string_literal: true
module ValidatesZipcode
class Formatter

WORD_CHAR_AND_DIGIT = /[A-Z0-9]/
WORD_CHAR_AND_DIGIT = /[A-Z0-9]/.freeze

ZIPCODES_TRANSFORMATIONS = {
AT: ->(z) { z.scan(/\d/).join },
CA: ->(z) { z.upcase.scan(WORD_CHAR_AND_DIGIT).insert(3, ' ').join },
CZ: ->(z) { z.scan(/\d/).insert(3, ' ').join },
DE: ->(z) { z.scan(/\d/).join.rjust(5, "0") },
DE: ->(z) { z.scan(/\d/).join.rjust(5, '0') },
GB: ->(z) { z.upcase.scan(WORD_CHAR_AND_DIGIT).insert(-4, ' ').join },
NL: ->(z) { z.upcase.scan(WORD_CHAR_AND_DIGIT).insert(4, ' ').join },
PL: ->(z) { z.scan(/\d/).insert(2, '-').join },
Expand All @@ -18,7 +18,7 @@ class Formatter
digits.insert(5, '-') if digits.count > 5
digits.join
}
}
}.freeze

def initialize(args = {})
@zipcode = args.fetch(:zipcode).to_s
Expand All @@ -36,6 +36,5 @@ def format
@zipcode.strip
end
end

end
end
end
2 changes: 1 addition & 1 deletion lib/validates_zipcode/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true
module ValidatesZipcode
VERSION = '0.3.1'
VERSION = '0.3.2'
end

0 comments on commit 050201e

Please sign in to comment.