fullname-matcher 1.0.0 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +0 -0
 - data/Gemfile +0 -0
 - data/fullname-matcher.gemspec +2 -2
 - data/lib/fullname/matcher/core.rb +16 -17
 - data/lib/fullname/matcher/version.rb +2 -2
 - metadata +14 -8
 
    
        data/.gitignore
    CHANGED
    
    | 
         
            File without changes
         
     | 
    
        data/Gemfile
    CHANGED
    
    | 
         
            File without changes
         
     | 
    
        data/fullname-matcher.gemspec
    CHANGED
    
    | 
         @@ -6,12 +6,12 @@ Gem::Specification.new do |s| 
     | 
|
| 
       6 
6 
     | 
    
         
             
              s.version     = Fullname::Matcher::VERSION
         
     | 
| 
       7 
7 
     | 
    
         
             
              s.platform    = Gem::Platform::RUBY
         
     | 
| 
       8 
8 
     | 
    
         
             
              s.authors     = ["xiaohui"]
         
     | 
| 
       9 
     | 
    
         
            -
              s.email       = [' 
     | 
| 
      
 9 
     | 
    
         
            +
              s.email       = ['xiaohui@zhangxh.net']
         
     | 
| 
       10 
10 
     | 
    
         
             
              s.summary     = "Match fullname in database"
         
     | 
| 
       11 
11 
     | 
    
         
             
              s.description = "Provide fullname, search in database with proper conditions"
         
     | 
| 
       12 
12 
     | 
    
         
             
              s.homepage    = 'https://github.com/xiaohui-zhangxh/fullname-matcher'
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
              s.files        = `git ls-files`.split("\n")
         
     | 
| 
       15 
15 
     | 
    
         
             
              s.require_path = 'lib'
         
     | 
| 
       16 
     | 
    
         
            -
              s.add_runtime_dependency(%q<fullname-parser>, [" 
     | 
| 
      
 16 
     | 
    
         
            +
              s.add_runtime_dependency(%q<fullname-parser>, [">= 1.0.3"])
         
     | 
| 
       17 
17 
     | 
    
         
             
            end
         
     | 
| 
         @@ -71,11 +71,10 @@ module Fullname::Matcher 
     | 
|
| 
       71 
71 
     | 
    
         | 
| 
       72 
72 
     | 
    
         
             
                  if match_list.size > 0
         
     | 
| 
       73 
73 
     | 
    
         
             
                    # 1. exactly match
         
     | 
| 
       74 
     | 
    
         
            -
                     
     | 
| 
       75 
     | 
    
         
            -
                       
     | 
| 
       76 
     | 
    
         
            -
                      r_middle_name.to_s.downcase.strip == name[:middle].to_s.downcase.strip
         
     | 
| 
      
 74 
     | 
    
         
            +
                    exact_match_list = match_list.select do |r|
         
     | 
| 
      
 75 
     | 
    
         
            +
                      compare_without_dot(r.send(@mapping[:middle]), name[:middle]) && compare_without_dot(r.send(@mapping[:suffix]), name[:suffix])
         
     | 
| 
       77 
76 
     | 
    
         
             
                    end
         
     | 
| 
       78 
     | 
    
         
            -
                    return  
     | 
| 
      
 77 
     | 
    
         
            +
                    return exact_match_list if exact_match_list.size > 0
         
     | 
| 
       79 
78 
     | 
    
         | 
| 
       80 
79 
     | 
    
         
             
                    # 2. if name[:middle] is not NULL, regexp match
         
     | 
| 
       81 
80 
     | 
    
         
             
                    if name[:middle]
         
     | 
| 
         @@ -88,9 +87,11 @@ module Fullname::Matcher 
     | 
|
| 
       88 
87 
     | 
    
         
             
                      # 2.1 fuzzy match: if middlename in DB is NULL, it matches
         
     | 
| 
       89 
88 
     | 
    
         
             
                      match_list_with_middlename = match_list.select{ |r| r.send(@mapping[:middle]).nil? }
         
     | 
| 
       90 
89 
     | 
    
         
             
                      return match_list_with_middlename if match_list_with_middlename.size > 0
         
     | 
| 
      
 90 
     | 
    
         
            +
                      # clear match list if don't match middlename
         
     | 
| 
      
 91 
     | 
    
         
            +
                      match_list = []
         
     | 
| 
       91 
92 
     | 
    
         
             
                    else
         
     | 
| 
       92 
93 
     | 
    
         
             
                      # 2.2 fuzzy match: assume all matches since name[:middle] is NULL
         
     | 
| 
       93 
     | 
    
         
            -
                      return match_list 
     | 
| 
      
 94 
     | 
    
         
            +
                      return match_list
         
     | 
| 
       94 
95 
     | 
    
         
             
                    end        
         
     | 
| 
       95 
96 
     | 
    
         
             
                  end
         
     | 
| 
       96 
97 
     | 
    
         | 
| 
         @@ -125,7 +126,7 @@ module Fullname::Matcher 
     | 
|
| 
       125 
126 
     | 
    
         
             
                  unless @options[:skip_match_suffix]
         
     | 
| 
       126 
127 
     | 
    
         
             
                    s1 = n1.suffix
         
     | 
| 
       127 
128 
     | 
    
         
             
                    s2 = n2.suffix
         
     | 
| 
       128 
     | 
    
         
            -
                    return false  if s1 && s2 && s1 
     | 
| 
      
 129 
     | 
    
         
            +
                    return false  if s1 && s2 && compare_without_dot(s1, s2) == false
         
     | 
| 
       129 
130 
     | 
    
         
             
                  end
         
     | 
| 
       130 
131 
     | 
    
         | 
| 
       131 
132 
     | 
    
         
             
                  return false if !abbr_match?(f1, f2)
         
     | 
| 
         @@ -156,24 +157,22 @@ module Fullname::Matcher 
     | 
|
| 
       156 
157 
     | 
    
         
             
                  matched_list = @table.all(:conditions => queries)
         
     | 
| 
       157 
158 
     | 
    
         
             
                  unless @options[:skip_match_suffix]
         
     | 
| 
       158 
159 
     | 
    
         | 
| 
       159 
     | 
    
         
            -
                    suffix = name[:suffix] ? name[:suffix].gsub('.', '').downcase.strip : nil
         
     | 
| 
       160 
     | 
    
         
            -
                    
         
     | 
| 
       161 
160 
     | 
    
         
             
                    # exactly match suffix
         
     | 
| 
       162 
     | 
    
         
            -
                     
     | 
| 
       163 
     | 
    
         
            -
                       
     | 
| 
       164 
     | 
    
         
            -
                       
     | 
| 
       165 
     | 
    
         
            -
                     
     | 
| 
       166 
     | 
    
         
            -
                    return matched_list_with_suffix if matched_list_with_suffix.size > 0
         
     | 
| 
      
 161 
     | 
    
         
            +
                    if name[:suffix].present?
         
     | 
| 
      
 162 
     | 
    
         
            +
                      matched_list_with_suffix = matched_list.select{|r| compare_without_dot(r.send(@mapping[:suffix]), name[:suffix]) }
         
     | 
| 
      
 163 
     | 
    
         
            +
                      return matched_list_with_suffix if matched_list_with_suffix.size > 0
         
     | 
| 
      
 164 
     | 
    
         
            +
                    end
         
     | 
| 
       167 
165 
     | 
    
         | 
| 
       168 
166 
     | 
    
         
             
                    # fuzzy match suffix( NULL matches NON-NULL )
         
     | 
| 
       169 
     | 
    
         
            -
                    return matched_list.select{|r|
         
     | 
| 
       170 
     | 
    
         
            -
                      r_suffix = r.send(@mapping[:suffix])
         
     | 
| 
       171 
     | 
    
         
            -
                      r_suffix.nil? || suffix.nil? || suffix == r_suffix.gsub('.', '').downcase.strip
         
     | 
| 
       172 
     | 
    
         
            -
                    }
         
     | 
| 
      
 167 
     | 
    
         
            +
                    return matched_list.select{|r| r.send(@mapping[:suffix]).to_s.strip.empty? || name[:suffix].nil? }
         
     | 
| 
       173 
168 
     | 
    
         | 
| 
       174 
169 
     | 
    
         
             
                  end
         
     | 
| 
       175 
170 
     | 
    
         
             
                  return matched_list
         
     | 
| 
       176 
171 
     | 
    
         
             
                end
         
     | 
| 
      
 172 
     | 
    
         
            +
             
     | 
| 
      
 173 
     | 
    
         
            +
                def compare_without_dot(str1, str2)
         
     | 
| 
      
 174 
     | 
    
         
            +
                  [str1, str2].map{|s| s.to_s.gsub('.', '').downcase.strip}.uniq.size == 1
         
     | 
| 
      
 175 
     | 
    
         
            +
                end
         
     | 
| 
       177 
176 
     | 
    
         | 
| 
       178 
177 
     | 
    
         
             
                def build_middlename_regexp(middlename)
         
     | 
| 
       179 
178 
     | 
    
         
             
                  middle_arr  = middlename.split(/[. ]+/)
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: fullname-matcher
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.0.5
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -9,22 +9,27 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2013- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2013-05-15 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: fullname-parser
         
     | 
| 
       16 
     | 
    
         
            -
              requirement:  
     | 
| 
      
 16 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       17 
17 
     | 
    
         
             
                none: false
         
     | 
| 
       18 
18 
     | 
    
         
             
                requirements:
         
     | 
| 
       19 
     | 
    
         
            -
                - -  
     | 
| 
      
 19 
     | 
    
         
            +
                - - ! '>='
         
     | 
| 
       20 
20 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       21 
     | 
    
         
            -
                    version: 1.0. 
     | 
| 
      
 21 
     | 
    
         
            +
                    version: 1.0.3
         
     | 
| 
       22 
22 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       23 
23 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       24 
     | 
    
         
            -
              version_requirements:  
     | 
| 
      
 24 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 25 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 26 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 27 
     | 
    
         
            +
                - - ! '>='
         
     | 
| 
      
 28 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 29 
     | 
    
         
            +
                    version: 1.0.3
         
     | 
| 
       25 
30 
     | 
    
         
             
            description: Provide fullname, search in database with proper conditions
         
     | 
| 
       26 
31 
     | 
    
         
             
            email:
         
     | 
| 
       27 
     | 
    
         
            -
            -  
     | 
| 
      
 32 
     | 
    
         
            +
            - xiaohui@zhangxh.net
         
     | 
| 
       28 
33 
     | 
    
         
             
            executables: []
         
     | 
| 
       29 
34 
     | 
    
         
             
            extensions: []
         
     | 
| 
       30 
35 
     | 
    
         
             
            extra_rdoc_files: []
         
     | 
| 
         @@ -58,8 +63,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       58 
63 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       59 
64 
     | 
    
         
             
            requirements: []
         
     | 
| 
       60 
65 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       61 
     | 
    
         
            -
            rubygems_version: 1.8. 
     | 
| 
      
 66 
     | 
    
         
            +
            rubygems_version: 1.8.25
         
     | 
| 
       62 
67 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       63 
68 
     | 
    
         
             
            specification_version: 3
         
     | 
| 
       64 
69 
     | 
    
         
             
            summary: Match fullname in database
         
     | 
| 
       65 
70 
     | 
    
         
             
            test_files: []
         
     | 
| 
      
 71 
     | 
    
         
            +
            has_rdoc: 
         
     |