Skip to content

Commit

Permalink
Supported pure?() method.
Browse files Browse the repository at this point in the history
Supported `fallback to pure` feature on JRuby.
  • Loading branch information
kiyoka committed Feb 14, 2012
1 parent 5ced917 commit fd987f2
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/fuzzystringmatch.rb
Expand Up @@ -17,7 +17,11 @@
#
require 'fuzzystringmatch/pure'
begin
require 'fuzzystringmatch/inline'
if RUBY_PLATFORM == "java"
STDERR.puts "Warning: native version is disabled on java platform. falled back to pure ruby version..."
else
require 'fuzzystringmatch/inline'
end
rescue LoadError
end

Expand Down
4 changes: 4 additions & 0 deletions lib/fuzzystringmatch/inline/jarowinkler.rb
Expand Up @@ -18,6 +18,10 @@
module FuzzyStringMatch
require 'inline'
class JaroWinklerInline
def pure?
false
end

inline do |builder|
builder.include '<iostream>'
builder.add_compile_flags '-x c++', '-lstdc++'
Expand Down
4 changes: 4 additions & 0 deletions lib/fuzzystringmatch/pure/jarowinkler.rb
Expand Up @@ -19,6 +19,10 @@ module FuzzyStringMatch
class JaroWinklerPure
THRESHOLD = 0.7

def pure?
true
end

def getDistance( s1, s2 )
a1 = s1.split( // )
a2 = s2.split( // )
Expand Down
2 changes: 2 additions & 0 deletions test/basic_native_spec.rb
Expand Up @@ -46,5 +46,7 @@
d2 = @jarow.getDistance("brittney spears", "brittney startzman")
d1 > d2
}.should be_true

@jarow.pure?( ).should == (RUBY_PLATFORM == "java")
end
end
2 changes: 2 additions & 0 deletions test/basic_pure_spec.rb
Expand Up @@ -46,5 +46,7 @@
d2 = @jarow.getDistance("brittney spears", "brittney startzman")
d1 > d2
}.should be_true

@jarow.pure?( ).should be_true
end
end
2 changes: 2 additions & 0 deletions test/mutibyte_spec.rb
Expand Up @@ -52,5 +52,7 @@
@jarow.getDistance( "まつもとゆきひろ", "まつもとひろゆき" ).should be_within(0.0001).of(0.9500)
@jarow.getDistance( "クライエント", "クライアント" ).should be_within(0.0001).of(0.9222)
@jarow.getDistance( "サーバー", "サーバ" ).should be_within(0.0001).of(0.9416)

@jarow.pure?( ).should be_true
end
end

0 comments on commit fd987f2

Please sign in to comment.