class Hulaki::SearchEngine

Public Class Methods

new() click to toggle source
# File lib/hulaki/search_engine.rb, line 6
def initialize
  contact_parser = Hulaki::ContactParser.new
  @csv_data = contact_parser.perform
end

Public Instance Methods

perform(search_data) click to toggle source
# File lib/hulaki/search_engine.rb, line 11
def perform(search_data)
  unless @csv_data.nil?
    search(search_data)
  end
end

Private Instance Methods

search_result(data) click to toggle source
# File lib/hulaki/search_engine.rb, line 26
def search_result(data)
  downcased_data = data.downcase.gsub(' ', '')
  @csv_data.map do |row|
    max_point = 0.0
    row.each do |col_head, v|
      keys_to_search.each do |key, weight|
        if col_head.to_s.downcase == key
          point = PairDistance.new(v.to_s.downcase).match(downcased_data)*weight
          max_point = point if max_point < point
          # puts "#{key} #{col_head} #{point} #{v} #{downcased_data}"
        end
      end
    end

    [row, max_point]
  end
end