alexrabarts-iso_country_codes 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.1.2 / 2008-11-24
2
+
3
+ * Inexact strings can now be used to search for country names
4
+
1
5
  === 0.1.1 / 2008-11-21
2
6
 
3
7
  * Each country now represented by a single class instead of one for each code
data/Manifest.txt CHANGED
@@ -2,7 +2,7 @@ History.txt
2
2
  Manifest.txt
3
3
  README.txt
4
4
  Rakefile
5
- iso-country-codes.gemspec
5
+ iso_country_codes.gemspec
6
6
  lib/iso_country_codes.rb
7
7
  lib/iso_country_codes/code.rb
8
8
  lib/iso_country_codes/iso_3166_1.rb
data/README.txt CHANGED
@@ -8,10 +8,6 @@ Provides ISO codes and names for countries.
8
8
 
9
9
  * Search by name or code (alpha-2, alpha-3 or numeric)
10
10
 
11
- == PROBLEMS:
12
-
13
- * Name search requires an exact match (although it is case-insensitive)
14
-
15
11
  == SYNOPSIS:
16
12
 
17
13
  # Finding an ISO code returns the country name and other code formats
@@ -29,6 +25,9 @@ Provides ISO codes and names for countries.
29
25
  # Codes can be found by country name
30
26
  IsoCountryCodes.find('australia')
31
27
 
28
+ # Inexact matches can also be found
29
+ IsoCountryCodes.find('united', :fuzzy => true).name # => 'United Kingdom'
30
+
32
31
  == INSTALL:
33
32
 
34
33
  * Via git:
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{iso_country_codes}
3
- s.version = "0.1.1"
3
+ s.version = "0.1.2"
4
4
 
5
5
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
6
  s.authors = ["Alex Rabarts"]
@@ -1,5 +1,5 @@
1
1
  class IsoCountryCodes # :nodoc:
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
 
4
4
  class UnknownCodeError < StandardError; end
5
5
 
@@ -8,7 +8,7 @@ class IsoCountryCodes # :nodoc:
8
8
  Code.all
9
9
  end
10
10
 
11
- def find(code)
11
+ def find(code, opts={})
12
12
  code = code.to_s.upcase
13
13
  instance = nil
14
14
 
@@ -24,6 +24,10 @@ class IsoCountryCodes # :nodoc:
24
24
  instance = all.select { |c| c.alpha3 == code }.first
25
25
  else
26
26
  instance = all.select { |c| c.name.upcase == code }.first
27
+ if opts[:fuzzy]
28
+ instance = all.select { |c| c.name.match(/^#{code}/i) }.first if instance.nil?
29
+ instance = all.select { |c| c.name.match(/#{code}/i) }.first if instance.nil?
30
+ end
27
31
  end
28
32
 
29
33
  raise UnknownCodeError, "ISO 3166-1 code '#{code}' does not exist." if instance.nil?
@@ -42,6 +42,13 @@ class TestIsoCountryCodes < Test::Unit::TestCase
42
42
  assert_equal IsoCountryCodes::Code::AUS.instance, IsoCountryCodes.find('Australia')
43
43
  end
44
44
 
45
+ def test_fuzzy_find
46
+ assert_equal IsoCountryCodes::Code::GBR.instance, IsoCountryCodes.find('united', :fuzzy => true)
47
+ assert_raises IsoCountryCodes::UnknownCodeError do
48
+ IsoCountryCodes.find('united')
49
+ end
50
+ end
51
+
45
52
  def test_get_numeric
46
53
  assert_equal '036', IsoCountryCodes::Code::AUS.numeric
47
54
  assert_equal '036', IsoCountryCodes::Code::AUS.instance.numeric
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alexrabarts-iso_country_codes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Rabarts