Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support Canadian Rate Centers #34

Merged
merged 3 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

A collection of useful data about [NANPA Rate Centers](https://en.wikipedia.org/wiki/Rate_center).

Data is currently sourced from [Simple Maps](https://simplemaps.com/data/us-cities) and [Local Calling Guide](https://localcallingguide.com/).
Data is currently sourced from [Simple Maps](https://simplemaps.com/) and [Local Calling Guide](https://localcallingguide.com/).

## Installation

Expand All @@ -26,9 +26,10 @@ gem install rate_centers

```rb
# Load rate centers
RateCenter.load(:rate_centers, only: { us: [:ny, :ca] }) # Loads rate centers in New York and California
RateCenter.load(:rate_centers, only: { us: [:ny, :ca], ca: [:on] }) # Loads rate centers in New York, California and Ontario, Canada
# RateCenter.load(:rate_centers, only: { us: { ny: [ "NWYRCYZN01" ], ca: [ "LSAN DA 01"] } }) # Loads only specific rate centers
# RateCenter.load(:rate_centers, only: { [ :us ] }) # Load all rate centers in US
# RateCenter.load(:rate_centers, only: { [ :ca ] }) # Load all rate centers in Canada
# RateCenter.load(:rate_centers, :all) # Load all rate centers

# RateCenter::RateCenter.all # returns all rate centers loaded
Expand All @@ -47,9 +48,10 @@ rate_center.closest_city.distance_km # 5.33

```rb
# Load cities
RateCenter.load(:cities, only: { us: [:ny, :ca] }) # Loads cities in New York and California
RateCenter.load(:cities, only: { us: [:ny, :ca], ca: [:on] }) # # Loads cities in New York, California and Ontario, Canada
# RateCenter.load(:cities, only: { us: { ny: [ "New York" ], ca: [ "Los Angeles"] } }) # Loads only specific cities
# RateCenter.load(:cities, only: { [ :us ] }) # Load all cities in US
# RateCenter.load(:rate_centers, only: { [ :ca ] }) # Load all rate centers in Canada
# RateCenter.load(:cities, :all) # Load all cities

# RateCenter::City.all # returns all cities loaded
Expand All @@ -58,25 +60,19 @@ city = RateCenter::City.find_by!(country: "US", region: "NY", name: "New York")
city.lat # "40.6943"
city.log # "-73.9249"
city.county # Queens
city.nearby_rate_centers.each do |rate_center|
city.nearby_rate_centers.first(10).each do |rate_center|
puts "Rate Center: #{rate_center.name}, Distance: #{rate_center.distance_km} km"
end
# Rate Center: NWYRCYZN01, Distance: 7.5 km
# Rate Center: NWYRCYZN03, Distance: 7.5 km
# Rate Center: NWYRCYZN04, Distance: 7.5 km
# Rate Center: NWYRCYZN05, Distance: 7.5 km
# Rate Center: NWYRCYZN06, Distance: 7.5 km
# Rate Center: NWYRCYZN07, Distance: 7.5 km
# Rate Center: NWYRCYZN08, Distance: 7.5 km
# Rate Center: NWYRCYZN09, Distance: 7.5 km
# Rate Center: NWYRCYZN10, Distance: 7.5 km
# Rate Center: NWYRCYZN11, Distance: 7.5 km
# Rate Center: NWYRCYZN12, Distance: 7.5 km
# Rate Center: NWYRCYZN13, Distance: 7.5 km
# Rate Center: NWYRCYZN14, Distance: 7.5 km
# Rate Center: NWYRCYZN15, Distance: 7.5 km
# Rate Center: NASSAUZN02, Distance: 18.96 km
# Rate Center: NASSAUZN03, Distance: 20.16 km
# Rate Center: ADDISLEHPK, Distance: 7.5 km
# Rate Center: ALBEKEN TR, Distance: 7.5 km
# Rate Center: ANNADALE, Distance: 7.5 km
# Rate Center: ARDEN HTS, Distance: 7.5 km
# Rate Center: ARLINGTON, Distance: 7.5 km
# Rate Center: ARROCHAR, Distance: 7.5 km
# Rate Center: ARVERNE, Distance: 7.5 km
# Rate Center: ASTORIA, Distance: 7.5 km
# Rate Center: BATH BEACH, Distance: 7.5 km
# Rate Center: BAY RIDGE, Distance: 7.5 km
```

### Not using Ruby?
Expand Down
4 changes: 2 additions & 2 deletions bin/update_data
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ data_directory = Pathname(File.expand_path("../data/", __dir__))
logger = Logger.new(STDOUT)

logger.info("Fetching city data from SimpleMaps")
RateCenter::DataSource::SimpleMaps.new.load_data!(data_directory: data_directory.join("cities/us"))
RateCenter::DataSource::SimpleMaps.new.load_data!(data_directory: data_directory.join("cities"))
logger.info("Fetching rate center data from LocalCallingGuide")
RateCenter::DataSource::LocalCallingGuide.new.load_data!(data_directory: data_directory.join("rate_centers/us"))
RateCenter::DataSource::LocalCallingGuide.new.load_data!(data_directory: data_directory.join("rate_centers"))
logger.info("Prepping data")
RateCenter::DataPrep.new(data_directory:).call
Loading