Module: Support::OfferParser
- Defined in:
- lib/support/offer_parser.rb
Constant Summary collapse
- LOCATION_DICT =
['location', 'based']
- KEYWORDS =
[ 'ruby', 'elixir', 'react', 'remote', 'graphql' ]
Class Method Summary collapse
- .get_keywords(content, keywords = KEYWORDS) ⇒ Object
- .get_location(content, dict = LOCATION_DICT) ⇒ Object
- .get_tokens(content) ⇒ Object
Class Method Details
.get_keywords(content, keywords = KEYWORDS) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# 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) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# 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) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/support/offer_parser.rb', line 43 def self.get_tokens(content) content .gsub(/\W+/, ' ') # remove non letters .downcase .split(/[\s-]/) end |