Skip to content

Commit

Permalink
添加原文和解析后数字对应的接口
Browse files Browse the repository at this point in the history
  • Loading branch information
qhwa committed Mar 19, 2014
1 parent e1621aa commit b73013d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/chinese_number.rb
Expand Up @@ -15,5 +15,11 @@ def extract text
Parser.new.parse( word )
end
end

def find text
text.scan( Parser::TOKEN ).map do |word|
{ word => Parser.new.parse( word ) }
end
end
end
end
7 changes: 7 additions & 0 deletions spec/chinese_number_spec.rb
Expand Up @@ -11,5 +11,12 @@
ChineseNumber.extract('每分钟六十秒的速度前进二十四小时').should == [60, 24]
end

it '可以寻找字符串内的中文数字' do
ChineseNumber.find('每分钟六十秒的速度前进二十四小时').should == [
{ '六十' => 60 },
{ '二十四' => 24 }
]
end

end

0 comments on commit b73013d

Please sign in to comment.