normalic 0.1.2 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,17 +14,43 @@ It tries to correct mal-formed input to the best of its ability.
14
14
  == Example
15
15
 
16
16
  >> address = Normalic::Address.parse("201 Varick St. floor 12th, New York, NY 10014")
17
+ >> address.number
18
+ => "201"
19
+
20
+ >> address.street
21
+ => "Varick"
22
+
17
23
  >> address.to_s
18
24
  => "201 Varick St., New York, NY 10014"
19
25
 
26
+
20
27
  >> phone = Normalic::PhoneNumber.parse("00 + 1* (212) 989-9741 ext. 123")
28
+ >> phone.npa
29
+ => "212"
30
+
21
31
  >> phone.to_s
22
32
  => "212 989 9741"
23
33
 
34
+
24
35
  >> uri = Normalic::URI.parse("github.com/ericxtang/expresso/../normalic/")
36
+ >> uri.domain
37
+ => "github"
38
+
39
+ >> uri.scheme
40
+ => "http"
41
+
25
42
  >> uri.to_s
26
43
  => "http://www.github.com/ericxtang/normalic"
27
44
 
45
+
46
+ >> addr = Normalic::Address.normalize_fields("address" => "201 Varick St.",
47
+ :city => "New York",
48
+ :state => "NY",
49
+ :zipcode => 10014)
50
+ >> addr.number
51
+ => "201"
52
+
53
+
28
54
  == Note on URI parsing behavior
29
55
 
30
56
  In the name of normalization, the URI class uses +http+ and +www+ as the
@@ -35,7 +35,7 @@ module Normalic
35
35
  user = url.cut!(/^.+@/) and user.cut!(/@$/)
36
36
  port = url.cut!(/:\d+$/) and port.cut!(/^:/)
37
37
  tld = url.cut!(/\.\w+$/) and tld.cut!(/^\./)
38
- domain = url.cut!(/(\.|\A)\w+$/) and domain.cut!(/^\./)
38
+ domain = url.cut!(/(\.|\A)[^\.]+$/) and domain.cut!(/^\./)
39
39
  subdomain = url.empty? ? 'www' : url
40
40
 
41
41
  return nil unless tld && domain
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "normalic"
5
- s.version = "0.1.2"
5
+ s.version = "0.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Eric Tang"]
9
- s.date = "2011-11-02"
9
+ s.date = "2011-11-01"
10
10
  s.description = "Normalize U.S addresses"
11
11
  s.email = "eric.x.tang@gmail.com"
12
12
  s.extra_rdoc_files = ["README.rdoc", "lib/constants.rb", "lib/normalic.rb", "lib/normalic/address.rb", "lib/normalic/phone_number.rb", "lib/normalic/uri.rb"]
13
- s.files = ["License.txt", "Manifest", "README.rdoc", "Rakefile", "lib/constants.rb", "lib/normalic.rb", "lib/normalic/address.rb", "lib/normalic/phone_number.rb", "lib/normalic/uri.rb", "normalic.gemspec", "spec/normalic_spec.rb"]
13
+ s.files = ["Manifest", "README.rdoc", "Rakefile", "lib/constants.rb", "lib/normalic.rb", "lib/normalic/address.rb", "lib/normalic/phone_number.rb", "lib/normalic/uri.rb", "spec/normalic_spec.rb", "normalic.gemspec"]
14
14
  s.homepage = "http://github.com/ericxtang/normalic"
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Normalic", "--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
@@ -1,4 +1,4 @@
1
- require 'lib/normalic'
1
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'normalic')
2
2
 
3
3
 
4
4
  describe "Normalic::URI" do
@@ -35,6 +35,20 @@ describe "Normalic::URI" do
35
35
  uri[:fragment].should == nil
36
36
  end
37
37
 
38
+ it "should parse a bare domain containing dashes" do
39
+ uri = Normalic::URI.parse("web-stuff.com")
40
+ uri.should_not be_nil
41
+ uri[:scheme].should == "http"
42
+ uri[:user].should == nil
43
+ uri[:subdomain].should == "www"
44
+ uri[:domain].should == "web-stuff"
45
+ uri[:tld].should == "com"
46
+ uri[:port].should == nil
47
+ uri[:path].should == "/"
48
+ uri[:query_hash].should == nil
49
+ uri[:fragment].should == nil
50
+ end
51
+
38
52
  it "should normalize consecutive slashes and strip trailing slashes in the path" do
39
53
  uri = Normalic::URI.parse("https://github.com/mkscrg//normalic/")
40
54
  uri[:scheme].should == "https"
metadata CHANGED
@@ -1,38 +1,28 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: normalic
3
- version: !ruby/object:Gem::Version
4
- hash: 31
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.2'
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 2
10
- version: 0.1.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Eric Tang
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-11-02 00:00:00 Z
12
+ date: 2011-11-01 00:00:00.000000000 Z
19
13
  dependencies: []
20
-
21
14
  description: Normalize U.S addresses
22
15
  email: eric.x.tang@gmail.com
23
16
  executables: []
24
-
25
17
  extensions: []
26
-
27
- extra_rdoc_files:
18
+ extra_rdoc_files:
28
19
  - README.rdoc
29
20
  - lib/constants.rb
30
21
  - lib/normalic.rb
31
22
  - lib/normalic/address.rb
32
23
  - lib/normalic/phone_number.rb
33
24
  - lib/normalic/uri.rb
34
- files:
35
- - License.txt
25
+ files:
36
26
  - Manifest
37
27
  - README.rdoc
38
28
  - Rakefile
@@ -41,46 +31,36 @@ files:
41
31
  - lib/normalic/address.rb
42
32
  - lib/normalic/phone_number.rb
43
33
  - lib/normalic/uri.rb
44
- - normalic.gemspec
45
34
  - spec/normalic_spec.rb
35
+ - normalic.gemspec
46
36
  homepage: http://github.com/ericxtang/normalic
47
37
  licenses: []
48
-
49
38
  post_install_message:
50
- rdoc_options:
39
+ rdoc_options:
51
40
  - --line-numbers
52
41
  - --inline-source
53
42
  - --title
54
43
  - Normalic
55
44
  - --main
56
45
  - README.rdoc
57
- require_paths:
46
+ require_paths:
58
47
  - lib
59
- required_ruby_version: !ruby/object:Gem::Requirement
48
+ required_ruby_version: !ruby/object:Gem::Requirement
60
49
  none: false
61
- requirements:
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- hash: 3
65
- segments:
66
- - 0
67
- version: "0"
68
- required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
55
  none: false
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- hash: 11
74
- segments:
75
- - 1
76
- - 2
77
- version: "1.2"
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '1.2'
78
60
  requirements: []
79
-
80
61
  rubyforge_project: normalic
81
- rubygems_version: 1.8.10
62
+ rubygems_version: 1.8.24
82
63
  signing_key:
83
64
  specification_version: 3
84
65
  summary: Normalize U.S addresses
85
66
  test_files: []
86
-
@@ -1,8 +0,0 @@
1
- Copyright (c) 2011 Eric Tang (eric.x.tang@gmail.com)
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
-