Permalink
Browse files

Tags can validly contain UN::Region codes

  • Loading branch information...
1 parent 0349e80 commit 671ebc022bcac284a061bb4f4a144260d2ac0d8f @tigrish committed Nov 9, 2012
Showing with 18 additions and 1 deletion.
  1. +1 −1 lib/iso/tag.rb
  2. +17 −0 spec/lib/iso/tag_spec.rb
View
@@ -5,7 +5,7 @@ class Tag
def initialize(code)
@code = code
@language = Language.identify(code)
- @region = Region.identify(code)
+ @region = Region.identify(code) || UN::Region.identify(code)
end
def codes
View
@@ -8,6 +8,12 @@
tag.region.code.should == 'MX'
end
+ it "returns a tag containing the language and UN region" do
+ tag = ISO::Tag.new('en-419')
+ tag.language.code.should == 'en'
+ tag.region.code.should == '419'
+ end
+
it "returns a tag containing the language only" do
tag = ISO::Tag.new('en-XXXXXX')
tag.language.code.should == 'en'
@@ -19,6 +25,12 @@
tag.language.should be_nil
tag.region.code.should == 'CH'
end
+
+ it "returns a tag containing the UN region only" do
+ tag = ISO::Tag.new('gsw-419')
+ tag.language.should be_nil
+ tag.region.code.should == '419'
+ end
it "returns a tag containing no language or region" do
tag = ISO::Tag.new('csb-XXXXXX')
@@ -62,6 +74,10 @@
ISO::Tag.new('da-AT').should be_valid
end
+ it "returns true when a valid language an UN region are supplied" do
+ ISO::Tag.new('es-419').should be_valid
+ end
+
it "returns false when no code is supplied" do
ISO::Tag.new('').should_not be_valid
end
@@ -73,5 +89,6 @@
it "returns false when supplied region is invalid" do
ISO::Tag.new('en-lol').should_not be_valid
end
+
end
end

0 comments on commit 671ebc0

Please sign in to comment.