zip5 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3982f4dded1b426a7add3df82e08a9affe2f885b
4
- data.tar.gz: 850bdc085e5cc52678f2e7335c5fd0cd8374cdc1
3
+ metadata.gz: b7c3edd5d43e8625eb9eb1adf9564483e1211373
4
+ data.tar.gz: 8e166debb115563f57903d944f03ea947a9afc01
5
5
  SHA512:
6
- metadata.gz: c3a66e397971e788e8ea1a68c4bf43fc9e69cd6a9f57eeda37249746b1ed74415c1b88fdb47a1312aa09f8ea98cf8d7ef82155c480f655a4019f3f7616487ef3
7
- data.tar.gz: 4fc6495ba4f502c46dd397c9f6fd31262055c6d8eb3124ae1f5741dbf8e916f627abdb8c82f41949fd288607ac07a17021726681640f8265131324dfae04f185
6
+ metadata.gz: 3be32884d951637bbc50ba19cd9bfe2604949ef8b403e4e56d33ae8d7ea7d3129403a6d37b46e6647242da540ea82a3efa4030886194b1dc3439fd76f68e1f6e
7
+ data.tar.gz: e4bdc489f11582a42816ccf206fe297959b220572a9a3147a9124a3b3136fbd07ce2fabc1570aa7a13c4b5262e1fadb0d6bff1d9c1cb14b3aceb89113dd0522b
@@ -0,0 +1,9 @@
1
+ 0.0.2 / 2016-08-02
2
+
3
+ * Enhancements
4
+
5
+ * Zip5.zip4 returns zip+4
6
+
7
+ 0.0.1 / 2014-05-16
8
+
9
+ Initial release!
@@ -4,7 +4,7 @@ module Zip5
4
4
  VALID = 501..99950
5
5
 
6
6
  def Zip5.zip5(input)
7
- input = input.to_i.to_s.delete('-')
7
+ input = input.to_i.to_s.gsub('-', '')
8
8
  memo = case input.length
9
9
  when 9
10
10
  input[0,5]
@@ -26,4 +26,19 @@ module Zip5
26
26
  end
27
27
  memo
28
28
  end
29
+
30
+ def Zip5.zip4(input)
31
+ input = input.to_s.gsub(/\.\d*\z/, '')
32
+ memo = nil
33
+ if input =~ /\A\d+\-(\d+)\z/
34
+ memo = $1.to_i
35
+ elsif zip5 = zip5(input)
36
+ hunk = zip5.gsub /\A0*/, ''
37
+ pat = /\A0*#{hunk}/
38
+ memo = input.gsub(pat, '').to_i
39
+ end
40
+ if memo and memo > 0
41
+ '%04d' % memo.to_i
42
+ end
43
+ end
29
44
  end
@@ -1,3 +1,3 @@
1
1
  module Zip5
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
@@ -1,2 +1,4 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
  require 'zip5'
3
+
4
+ require 'pry'
@@ -2,27 +2,34 @@ require 'spec_helper'
2
2
 
3
3
  describe Zip5 do
4
4
  {
5
- 999501234 => '99950',
6
- '99950-1234' => '99950',
7
- 57531234 => '05753',
8
- '5753-1234' => '05753',
9
- '05753-1234' => '05753',
10
- 5011234 => '00501',
11
- 99950 => '99950',
12
- 5753 => '05753',
13
- 1000 => '01000',
14
- 501 => '00501',
15
- '' => nil,
16
- 'abc' => nil,
5
+ 999500004 => ['99950', '0004'],
6
+ '99950-0004' => ['99950', '0004'],
7
+ 57530004 => ['05753', '0004'],
8
+ '5753-0004' => ['05753', '0004'],
9
+ '05753-0004' => ['05753', '0004'],
10
+ 5010004 => ['00501', '0004'],
11
+ '99950-4' => ['99950', '0004'],
12
+ '5753-4' => ['05753', '0004'],
13
+ '05753-4' => ['05753', '0004'],
14
+ 99950 => ['99950', nil],
15
+ 5753 => ['05753', nil],
16
+ 1000 => ['01000', nil],
17
+ 501 => ['00501', nil],
18
+ '' => [nil, nil],
19
+ 'abc' => [nil, nil],
17
20
  }.each do |input, expected|
18
- it "parses #{input.inspect} as #{expected.inspect}" do
19
- expect(Zip5.zip5(input)).to eq(expected)
21
+ it "parses #{input.inspect} as #{expected.compact.join('-')}" do
22
+ zip5, zip4 = expected
23
+ expect(Zip5.zip5(input)).to eq(zip5)
24
+ expect(Zip5.zip4(input)).to eq(zip4)
20
25
  end
21
- # here we also test 57531234.0, etc.
26
+ # here we also test 57530004.0, etc.
22
27
  if input.is_a?(Integer)
23
28
  input_f = input.to_f
24
- it "parses #{input_f.inspect} as #{expected.inspect}" do
25
- expect(Zip5.zip5(input_f)).to eq(expected)
29
+ it "parses #{input_f.inspect} as #{expected.compact.join('-')}" do
30
+ zip5, zip4 = expected
31
+ expect(Zip5.zip5(input_f)).to eq(zip5)
32
+ expect(Zip5.zip4(input_f)).to eq(zip4)
26
33
  end
27
34
  end
28
35
  end
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.6"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency 'pry'
24
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zip5
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seamus Abshere
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-16 00:00:00.000000000 Z
11
+ date: 2016-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: For example, 8840 means 08840 and 5011234 means 00501-1234.
56
70
  email:
57
71
  - seamus@abshere.net
@@ -62,6 +76,7 @@ files:
62
76
  - ".gitignore"
63
77
  - ".rspec"
64
78
  - ".travis.yml"
79
+ - CHANGELOG
65
80
  - Gemfile
66
81
  - LICENSE.txt
67
82
  - README.md
@@ -91,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
106
  version: '0'
92
107
  requirements: []
93
108
  rubyforge_project:
94
- rubygems_version: 2.2.2
109
+ rubygems_version: 2.5.1
95
110
  signing_key:
96
111
  specification_version: 4
97
112
  summary: Convert United States zip codes to their correct Zip5 representation, even