alexarrufat / address_composer Goto Github PK
View Code? Open in Web Editor NEWRuby address composer
License: MIT License
Ruby address composer
License: MIT License
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
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"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.