address_line_divider 1.0.0 → 1.0.5

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
  SHA256:
3
- metadata.gz: 9c5b8e69f1963cfab356451c3d2b564fc348bcbe590457d19fe04cb2ff209bfa
4
- data.tar.gz: eff6e856b809c91491dbc064f9eb98a04802656adba992a0b45db1d326f662e8
3
+ metadata.gz: 35c739931b4af196ad0a5dc9181106b9484c849e6a27a907f75afb407647a9f8
4
+ data.tar.gz: 90db5541183059ea3a59a99b76f9bb9eb4aae261af4c07a7de3add6c560c1418
5
5
  SHA512:
6
- metadata.gz: 5e0098cf08361f38ef9effbf67690c8eb5d5861012d921a093320bd153e40ae7d919a1fcb845f4e1eb9ffe5b994a11dbc1db2b3d42b24b5bd2954693dc5b5e51
7
- data.tar.gz: 91a129106423fffe21df38f102466015d63d6625c8069d8d7d1b7e03158ac84133dbeaeb5781318292446a33c7fe36f61cd0aff59e339a69c6402895d38ca8fe
6
+ metadata.gz: 1b7ef4b0b5261404a42c9c72e58128e4f229ba99442e49fd5edf4369e4ce41e6f54006280e7fb2dda672f13e87ba3ede8d8f25ff18c53077a20f432288cf787a
7
+ data.tar.gz: a4aede3d31b69bac9e7ea051cac8f235b27fc8a083b96eccfdcdbe6ea687003fd6e38473ee63c2d0baeec99ee3c99cb07d892737c03c462628bf167342e4a19a
@@ -0,0 +1,31 @@
1
+ name: CD
2
+
3
+ on:
4
+ pull_request:
5
+ types: [closed]
6
+
7
+ jobs:
8
+ log:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - name: Log
12
+ run: |
13
+ echo "GITHUB_REF: $GITHUB_REF"
14
+ echo "github.head_ref: ${{ github.head_ref }}"
15
+ echo "github.base_ref: ${{ github.base_ref }}"
16
+ echo "contains(github.head_ref, 'release/v'): ${{ contains(github.head_ref, 'release/v') }}"
17
+ echo "github.base_ref == 'master': ${{ github.base_ref == 'master' }}"
18
+ echo "github.event.pull_request.merged: ${{ github.event.pull_request.merged }}"
19
+ cd:
20
+ runs-on: ubuntu-latest
21
+ if: ${{ contains(github.head_ref, 'release/v') && github.base_ref == 'master' && github.event.pull_request.merged == true }}
22
+ steps:
23
+ - uses: actions/checkout@v2
24
+
25
+ - name: Release Gem
26
+ uses: cadwallion/publish-rubygems-action@master
27
+ env:
28
+ GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
29
+ RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
30
+ RELEASE_COMMAND: bundle exec rake release
31
+
@@ -1,9 +1,9 @@
1
- name: Ruby
1
+ name: CI
2
2
 
3
- on: [push,pull_request]
3
+ on: [push]
4
4
 
5
5
  jobs:
6
- build:
6
+ ci:
7
7
  runs-on: ubuntu-latest
8
8
  steps:
9
9
  - uses: actions/checkout@v2
data/.rubocop.yml CHANGED
@@ -1,3 +1,12 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+
4
+ Metrics/BlockLength:
5
+ Enabled: false
6
+
7
+ Style/Documentation:
8
+ Enabled: false
9
+
1
10
  Style/StringLiterals:
2
11
  Enabled: true
3
12
  EnforcedStyle: double_quotes
data/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # Changelog
2
-
3
- ## V1.0.0
2
+ ## v1.0.5
3
+ * Verify results and return nil if it's invalid.
4
+ ## v1.0.4
5
+ * Improve Regex
6
+ ## v1.0.3
7
+ * Small fixes
8
+ * CI Status badge
9
+ ## v1.0.2
10
+ * Add MIT LICENSE
11
+ ## v1.0.0
4
12
  ### Initial version
5
13
  #### Features
6
14
  * Parse address lines using a Regex
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- address_line_divider (1.0.0)
4
+ address_line_divider (1.0.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Matias Albarello
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,3 +1,6 @@
1
+ [![Ruby](https://github.com/matiasalbarello/address_line_divider/actions/workflows/main.yml/badge.svg)](https://github.com/matiasalbarello/address_line_divider/actions/workflows/main.yml)
2
+ [![Maintainability](https://api.codeclimate.com/v1/badges/a99a88d28ad37a79dbf6/maintainability)](https://codeclimate.com/github/codeclimate/codeclimate/maintainability)
3
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/a99a88d28ad37a79dbf6/test_coverage)](https://codeclimate.com/github/codeclimate/codeclimate/test_coverage)
1
4
  # AddressLineDivider
2
5
 
3
6
  The purpose of this GEM is to provide a tool to correctly parse address lines into Street + Street Number. Sometimes it's trivial and it can be solved with a regular expression, but when the street itself contains numbers, the task needs some extra considerations.
@@ -7,10 +7,11 @@ Gem::Specification.new do |spec|
7
7
  spec.version = AddressLineDivider::VERSION
8
8
  spec.authors = ["Matias Albarello"]
9
9
  spec.email = ["matias.albarello@gmail.com"]
10
+ spec.licenses = ["MIT"]
10
11
 
11
12
  spec.summary = "Divide an address line into street and street number based on a Streets file."
12
13
  spec.homepage = "https://github.com/matiasalbarello/address_line_divider"
13
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
14
15
 
15
16
  spec.metadata["homepage_uri"] = spec.homepage
16
17
  spec.metadata["source_code_uri"] = spec.homepage
@@ -10,14 +10,37 @@ module AddressLineDivider
10
10
  street = search_street_on_file(address_line)
11
11
  return [street, street_no(address_line, street)] if street
12
12
 
13
- parse_using_regex(address_line)
13
+ result = parse_using_regex(address_line)
14
+ result unless result.nil? || result.any?(:nil?)
14
15
  end
15
16
 
16
17
  private
17
18
 
18
19
  def parse_using_regex(address_line)
19
- /^(?<street>\D+) (?<street_no>.*)/ =~ address_line
20
- [street, street_no]
20
+ last_number = last_number(address_line)
21
+ return unless last_number
22
+
23
+ last_number_index = address_line.index(last_number)
24
+ street_name = address_line[0..last_number_index - 1].strip
25
+ street_no = address_line[last_number_index..-1].strip
26
+
27
+ return if invalid_result(address_line, [street_name, street_no])
28
+
29
+ [street_name, street_no]
30
+ end
31
+
32
+ def invalid_result(address_line, result)
33
+ squish(result.join(" ")) != squish(address_line)
34
+ end
35
+
36
+ def last_number(address_line)
37
+ squish(address_line).split(" ").select do |substr|
38
+ substr =~ /[[:digit:]]/
39
+ end.last
40
+ end
41
+
42
+ def squish(string)
43
+ string.gsub(" ", " ").strip
21
44
  end
22
45
 
23
46
  def search_street_on_file(address_line)
@@ -35,4 +58,4 @@ module AddressLineDivider
35
58
  address_line.gsub(street, "").strip
36
59
  end
37
60
  end
38
- end
61
+ end
@@ -10,8 +10,9 @@ module AddressLineDivider
10
10
  return if path.nil?
11
11
 
12
12
  raise FileNotFound, "Couldn't find a file with the path `#{path}`." unless File.exist? path
13
+
13
14
  @streets_file_path = path
14
15
  end
15
16
  end
16
17
  end
17
- end
18
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AddressLineDivider
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.5"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: address_line_divider
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matias Albarello
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-13 00:00:00.000000000 Z
11
+ date: 2021-07-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -17,6 +17,7 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - ".github/workflows/cd.yml"
20
21
  - ".github/workflows/main.yml"
21
22
  - ".gitignore"
22
23
  - ".rspec"
@@ -25,6 +26,7 @@ files:
25
26
  - CODE_OF_CONDUCT.md
26
27
  - Gemfile
27
28
  - Gemfile.lock
29
+ - LICENSE
28
30
  - README.md
29
31
  - Rakefile
30
32
  - address_line_divider.gemspec
@@ -35,7 +37,8 @@ files:
35
37
  - lib/address_line_divider/configuration.rb
36
38
  - lib/address_line_divider/version.rb
37
39
  homepage: https://github.com/matiasalbarello/address_line_divider
38
- licenses: []
40
+ licenses:
41
+ - MIT
39
42
  metadata:
40
43
  homepage_uri: https://github.com/matiasalbarello/address_line_divider
41
44
  source_code_uri: https://github.com/matiasalbarello/address_line_divider
@@ -48,7 +51,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
48
51
  requirements:
49
52
  - - ">="
50
53
  - !ruby/object:Gem::Version
51
- version: 2.3.0
54
+ version: 2.4.0
52
55
  required_rubygems_version: !ruby/object:Gem::Requirement
53
56
  requirements:
54
57
  - - ">="