Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generate individual dbstore for each locale
and move finders to StreetNames::Finder
- Loading branch information
Showing
10 changed files
with
64 additions
and
44 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
require 'street_names/parser' | ||
require 'street_names/database' | ||
require 'street_names/finder' | ||
|
||
module StreetNames | ||
|
||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module StreetNames | ||
class Finder | ||
attr_reader :streets | ||
|
||
def initialize locale=LOCALE | ||
@database = StreetNames::Database.new locale | ||
convert! | ||
end | ||
|
||
[ :postcode, :name, :area ].each do |key| | ||
define_method(:"find_by_#{key}") do |value| | ||
@streets.select { |street| eval("street.#{key}") == value } | ||
end | ||
end | ||
|
||
private | ||
|
||
def convert! | ||
@streets = @database.load_streets.map do |street| | ||
Street.new [ street[:name], street[:postcode], street[:area] ] | ||
end | ||
end | ||
|
||
|
||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'spec_helper' | ||
describe StreetNames::Finder do | ||
|
||
let (:street_finder) { StreetNames::Finder.new "en" } | ||
|
||
it 'load streets from spreadsheet' do | ||
street = { :name => "Agias Marinas", :postcode => 8041, :area => "Pafos"} | ||
|
||
street_finder.streets.map(&:to_json).should include street.to_json | ||
end | ||
|
||
context '#finders' do | ||
let(:street) { { :name => "Dimosthenous Georgiou", :postcode => 8020, :area => "Pafos"} } | ||
|
||
it 'find streets by postcode' do | ||
street_finder.find_by_postcode(8020).map(&:to_json).should include street.to_json | ||
end | ||
|
||
it 'find street by name' do | ||
street_finder.find_by_name("Dimosthenous Georgiou").map(&:to_json).should include street.to_json | ||
end | ||
|
||
it 'find area by street name' do | ||
street_finder.find_by_area("Pafos").map(&:to_json).should include street.to_json | ||
end | ||
end | ||
end |
This file contains 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