Skip to content

Commit

Permalink
Added NumberRecognizer#type back as a composite of country name and m…
Browse files Browse the repository at this point in the history
…obile/landline status
  • Loading branch information
Narnach committed Feb 22, 2011
1 parent 545d55b commit d3d3b1d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/number_recognizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,17 @@ def correct(country_bias=nil)
valid?
end

def type
return nil unless valid?
"#{country_name} #{mobile? ? "mobile" : "landline"}"
end

private

def parse
@parsed = true
@valid = false
number = self.number.to_s
number = self.number.to_s.sub(/^0+/,'')
format = self.class.formats.find {|format| number.match(format[:format])}
unless format
return
Expand Down
17 changes: 15 additions & 2 deletions spec/number_recognizer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@
@nc.local_number.should == '913773785'
end

it "should return false for a landline number" do
@nc = NumberRecognizer.new('31201234567')
@nc.should_not be_valid_or_correct_mobile
end
end

describe 'mobile?' do
Expand All @@ -219,9 +223,18 @@
@nc.should be_mobile
end

it 'should recognize 31202345678 as not mobile number' do
@nc = NumberRecognizer.new('31202345678')
it 'should recognize 31201234567 as not mobile number' do
@nc = NumberRecognizer.new('31201234567')
@nc.should_not be_mobile
end
end

describe "type" do
it "should compose country and mobile/landline status" do
@nc = NumberRecognizer.new('31612345678')
@nc.type.should == "Netherlands mobile"
@nc = NumberRecognizer.new('31201234567')
@nc.type.should == "Netherlands landline"
end
end
end

0 comments on commit d3d3b1d

Please sign in to comment.