Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

region-spotter

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

region-spotter

  • 1.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Spotter

Robustly identify countries, states, islands, cities and whatnot from text. This is still BETA. Although it supports most countries and states, it still lacks regions and cities for the most part of the world.

Description

What if I ask you: "What region is 'ontario'", or "where is 'ca'"? I would answer: Ontario is a state in Canada as well as a city in California. CA is the ISO abbreviation for Canada, and also the abbreviation for California.

The goal of this gem is such: Given a string, do your very best to identify all possible locations, and order them by significance. Provide as much information as possible; What kind of region is this? Country? City? Island? Continent?

Usage

require 'spotter'

spotter = Spotter.new

results = spotter.identify('new york')

puts results.first.to_s # => "United States, New York"

puts results.first.regions[0].name # => "United States"
puts results.first.regions[0].type # => "country"
puts results.first.regions[1].name # => "New York"
puts results.first.regions[1].type # => "state"

It can handle text in different cases, spellings, etc.

spotter.identify('ontARIO, california').first.to_s 
 # => "United States, California, San Bernardino, Ontario"

spotter.identify('росСиЯ').first.to_s # => 'Russia'
spotter.identify('ruSSia').first.to_s # => 'Russia'

It returns all matches found:

results = spotter.identify('canada')
puts results[0].to_s # => 'Canada'
puts results[1].to_s # => 'United States, Kansas, Canada'

It works with abbreviations too:

puts spotter.identify('se').first.to_s # => 'Sweden'

Rake task

You can also use the gem with the rake task identify as such:

rake identify['new york']

TODO

  • Add support for more states, cities and other regions
  • Add support for html/bbcode tagging of search queries, showing identified parts of the string

FAQs

Package last updated on 09 Jul 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc