Git Product home page Git Product logo

address_composer's People

Contributors

dependabot[bot] avatar martincabrera avatar sergiogomez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

address_composer's Issues

NoMethodError: undefined method `match?' for nil:NilClass

Given a wrongly parsed address that has no state and a country containing a number: e.g.

{"road"=>"c. sánchez pacheco", "house_number"=>"46", "postcode"=>"28002", "city"=>"madrid", "country"=>"españa 1b"}

address_composer.rb:184

# If country is a number use the state as country
    if components["country"]&.match?(/[0-9]/)
      components["country"] = components["state"]
    end
# => {"road"=>"c. sánchez pacheco", "house_number"=>"46", "postcode"=>"28002", "city"=>"madrid", "country"=>nil}
 
 # Remove components with URL
    components.delete_if { |_, v| v.match?(URI::DEFAULT_PARSER.make_regexp) }
# => NoMethodError: undefined method `match?' for nil:NilClass

Unit duplicated when compose

Given an address with a unit, it seems to be used twice when compose.

This is an example:

require "address_composer"
require "ruby_postal/parser"

address = "W13 8AA, United Kingdom, London, 12 Argyle Road, Flat 6"

parsed_address = Postal::Parser.parse_address(address)
# => [{:label=>:postcode, :value=>"w13 8aa"}, {:label=>:country, :value=>"united kingdom"}, {:label=>:road, :value=>"london"}, {:label=>:house_number, :value=>"12"}, {:label=>:road, :value=>"argyle road"}, {:label=>:unit, :value=>"flat 6"}]

components = parsed_address.each_with_object({}) do |component, hash|
  hash[component[:label].to_s] = component[:value]
end
# => {"postcode"=>"w13 8aa", "country"=>"united kingdom", "road"=>"argyle road", "house_number"=>"12", "unit"=>"flat 6"}

AddressComposer.compose(components)
#  => "w13 8aa united kingdom argyle road 12 flat 6 flat 6\n"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.