address_line_divider 1.0.2 → 1.0.6

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: ab33cb2334436bfab10c543f40ebc441fc13b7a61e9ae4d8ffccd7199394d6d3
4
- data.tar.gz: ed9bbc34a12bac864772027ae73299ff76b0ac8c4fb808a00698fdb0e0b04811
3
+ metadata.gz: 678fdc52d5f68e75e97ff2f67d260c325747273287c4e0fe7054dbca7258277c
4
+ data.tar.gz: 1c5b3ffda58132cafcf8632d06a1b77243cccd096b680a634f3b0b7ca070164c
5
5
  SHA512:
6
- metadata.gz: 04e1de519f1c6427d07a15f5d222b16ff6da46f9ee6f8b680d628333cd1f43993552122ebd9ab048bccef8529945b30388ab8c6a0c2d67bd891c88967267fc4d
7
- data.tar.gz: 1e427cf8c1e54f8357eeb7baeb9be7f9562cf65c01dcb53591b87bc591ac70a609646094cfda90bbbdd19a11adc02cd7b63ad120bcb5cf2ef38436a61991f7b2
6
+ metadata.gz: b02307bdbad519d388d2f3c97d1849b61404c1629174c90f2b43026371fdaeeb387013d0528e51687b65ad99c0c52ec8b62de19b1aa90d3e9b1cab06fcaf8d68
7
+ data.tar.gz: 66a5ddc6ed60ec17c49683e9e017ae114ebb65130c3b21bb885152923e3e0cd02649003157e5e125d7cc2f1a64f633fffa264cd113f1b77e8a923510ef44b1d8
@@ -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/.gitignore CHANGED
@@ -9,3 +9,5 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
13
+ .byebug_history
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,8 +1,16 @@
1
1
  # Changelog
2
-
3
- ## V1.0.2
2
+ ## v1.0.6
3
+ * Improve verifying results.
4
+ ## v1.0.5
5
+ * Verify results and return nil if it's invalid.
6
+ ## v1.0.4
7
+ * Improve Regex
8
+ ## v1.0.3
9
+ * Small fixes
10
+ * CI Status badge
11
+ ## v1.0.2
4
12
  * Add MIT LICENSE
5
- ## V1.0.0
13
+ ## v1.0.0
6
14
  ### Initial version
7
15
  #### Features
8
16
  * 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.2)
4
+ address_line_divider (1.0.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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,11 +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
+ spec.licenses = ["MIT"]
11
11
 
12
12
  spec.summary = "Divide an address line into street and street number based on a Streets file."
13
13
  spec.homepage = "https://github.com/matiasalbarello/address_line_divider"
14
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
15
15
 
16
16
  spec.metadata["homepage_uri"] = spec.homepage
17
17
  spec.metadata["source_code_uri"] = spec.homepage
@@ -8,16 +8,41 @@ module AddressLineDivider
8
8
 
9
9
  def parse(address_line)
10
10
  street = search_street_on_file(address_line)
11
- return [street, street_no(address_line, street)] if street
11
+ result = [street, street_no(address_line, street)] if street
12
+ result ||= parse_using_regex(address_line)
12
13
 
13
- parse_using_regex(address_line)
14
+ return if invalid_result(address_line, result)
15
+
16
+ result
14
17
  end
15
18
 
16
19
  private
17
20
 
18
21
  def parse_using_regex(address_line)
19
- /^(?<street>\D+) (?<street_no>.*)/ =~ address_line
20
- [street, street_no]
22
+ last_number = last_number(address_line)
23
+ return unless last_number
24
+
25
+ last_number_index = address_line.index(last_number)
26
+ street_name = address_line[0..last_number_index - 1].strip
27
+ street_no = address_line[last_number_index..-1].strip
28
+
29
+ [street_name, street_no]
30
+ end
31
+
32
+ def invalid_result(address_line, result)
33
+ result.nil? ||
34
+ result.any? { |r| r.nil? || r.strip.empty? } ||
35
+ squish(result.join(" ")) != squish(address_line)
36
+ end
37
+
38
+ def last_number(address_line)
39
+ squish(address_line).split(" ").select do |substr|
40
+ substr =~ /[[:digit:]]/
41
+ end.last
42
+ end
43
+
44
+ def squish(string)
45
+ string.gsub(" ", " ").strip
21
46
  end
22
47
 
23
48
  def search_street_on_file(address_line)
@@ -35,4 +60,4 @@ module AddressLineDivider
35
60
  address_line.gsub(street, "").strip
36
61
  end
37
62
  end
38
- end
63
+ 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.2"
4
+ VERSION = "1.0.6"
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.2
4
+ version: 1.0.6
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"
@@ -50,7 +51,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
50
51
  requirements:
51
52
  - - ">="
52
53
  - !ruby/object:Gem::Version
53
- version: 2.3.0
54
+ version: 2.4.0
54
55
  required_rubygems_version: !ruby/object:Gem::Requirement
55
56
  requirements:
56
57
  - - ">="