module Support::OfferParser
Constants
- KEYWORDS
- LOCATION_DICT
Public Class Methods
get_keywords(content, keywords = KEYWORDS)
click to toggle source
# File lib/support/offer_parser.rb, line 29 def self.get_keywords(content, keywords = KEYWORDS) indexes = Array.new tokens = get_tokens(content) indexes = keywords.map { |q| [tokens.find_index(q), q] } keywords = Array.new indexes.each do |index| next if index[0].nil? keywords << tokens[index[0]].gsub(',', '') end keywords.map(&:capitalize).join(', ') end
get_location(content, dict = LOCATION_DICT)
click to toggle source
# File lib/support/offer_parser.rb, line 13 def self.get_location(content, dict = LOCATION_DICT) indexes = Array.new tokens = get_tokens(content) indexes = dict.map { |q| [tokens.find_index(q), q] } locations = Array.new indexes.each do |index| next if index[0].nil? locations << tokens[index[0] + 1] if index[1] == 'location' locations << tokens[index[0] - 1..index[0] + 2] if index[1] == 'based' end locations.join(' ').capitalize end
get_tokens(content)
click to toggle source
# File lib/support/offer_parser.rb, line 43 def self.get_tokens(content) content .gsub(/\W+/, ' ') # remove non letters .downcase .split(/[\s-]/) end