Created
May 30, 2009 22:42
-
-
Save sprite2005/120666 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Migration: | |
class CreateOutboundRates < ActiveRecord::Migration | |
def self.up | |
create_table :outbound_rates do |t| | |
t.string :destination | |
t.integer :prefix | |
t.integer :rate_in_cents | |
t.timestamps | |
end | |
add_index :outbound_rates, :prefix | |
end | |
def self.down | |
drop_table :outbound_rates | |
end | |
end | |
Model: | |
class OutboundRate < ActiveRecord::Base | |
money :rate | |
end | |
Task: | |
I need a finder function that will take any arbitrary number and return the most specific match based on prefix in the most efficient manner possible (there are 16,000 records). | |
Example records: | |
[1] ALGERIA - MOBILE - MOBILIS,21366,0.1784 | |
[2] ALGERIA - MOBILE - MOBILIS,213697,0.1784 | |
[3] ALGERIA - MOBILE - MOBILIS,213698,0.1784 | |
[4] ALGERIA - MOBILE - ORASCOM,21391,0.2057 | |
So if given the number 21366234324 it would match record number 1, if given 2136973432 it would match record number 2. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment