Skip to content

Commit

Permalink
[ifmeorg#1713] rubocop cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
S-Warmenhoven committed Apr 9, 2020
1 parent 410e72b commit 319fab3
Showing 1 changed file with 49 additions and 51 deletions.
100 changes: 49 additions & 51 deletions app/services/resource_recommendation.rb
Original file line number Diff line number Diff line change
@@ -1,56 +1,54 @@

# frozen_string_literal: true
class ResourceRecommendation

def initialize(moment)
@moment = moment
end
def initialize(moment)
@moment = moment
end

def resources
all_resources = JSON.parse(File.read(Rails.root.join('doc', 'pages', 'resources.json')))
matched_resources = []
moment_keywords = []
moment_name = @moment.name.split
moment_why = ActionController::Base.helpers.strip_tags(@moment.why).split
moment_fix = ActionController::Base.helpers.strip_tags(@moment.fix).split
@moment.categories.each do |category|
moment_keywords.push(category['name'].split)
end
@moment.categories.each do |category|
category_description = ActionController::Base.helpers.strip_tags(category['description'])
moment_keywords.push(category_description.split)
end
@moment.moods.each do |mood|
moment_keywords.push(mood['name'].split)
end
@moment.moods.each do |mood|
mood_description = ActionController::Base.helpers.strip_tags(mood['description'])
moment_keywords.push(mood_description.split)
end
@moment.strategies.each do |strategy|
moment_keywords.push(strategy['name'].split)
end
@moment.strategies.each do |strategy|
strategy_description = ActionController::Base.helpers.strip_tags(strategy['description'])
moment_keywords.push(strategy_description.split)
end
moment_keywords.push(moment_name, moment_why, moment_fix)
moment_keywords = moment_keywords.flatten
moment_keywords.each do |keyword|
keyword.gsub!(/([_@#!%()\-=;><,{}\~\[\]\.\/\?\"\*\^\$\+\-]+)/, '')
def resources
all_resources = JSON.parse(File.read(Rails.root.join('doc', 'pages', 'resources.json')))
matched_resources = []
moment_keywords = []
moment_name = @moment.name.split
moment_why = ActionController::Base.helpers.strip_tags(@moment.why).split
moment_fix = ActionController::Base.helpers.strip_tags(@moment.fix).split
@moment.categories.each do |category|
moment_keywords.push(category['name'].split)
end
@moment.categories.each do |category|
category_description = ActionController::Base.helpers.strip_tags(category['description'])
moment_keywords.push(category_description.split)
end
@moment.moods.each do |mood|
moment_keywords.push(mood['name'].split)
end
@moment.moods.each do |mood|
mood_description = ActionController::Base.helpers.strip_tags(mood['description'])
moment_keywords.push(mood_description.split)
end
@moment.strategies.each do |strategy|
moment_keywords.push(strategy['name'].split)
end
@moment.strategies.each do |strategy|
strategy_description = ActionController::Base.helpers.strip_tags(strategy['description'])
moment_keywords.push(strategy_description.split)
end
moment_keywords.push(moment_name, moment_why, moment_fix)
moment_keywords = moment_keywords.flatten
moment_keywords.each do |keyword|
keyword.gsub!(%r{([_@#!%()\-=;><,{}\~\[\]\./\?\"\*\^\$\+\-]+)}, '')
end
moment_keywords = moment_keywords.map(&:downcase)
all_resources.each do |resource|
resource_tags = resource['tags']
resource_tags.each do |tag|
tag.gsub!(%r{([_@#!%()\-=;><,{}\~\[\]\./\?\"\*\^\$\+\-]+)}, ' ')
tag.split
end
moment_keywords = moment_keywords.map(&:downcase)
all_resources.each do |resource|
resource_tags = resource['tags']
resource_tags.each do |tag|
tag.gsub!(/([_@#!%()\-=;><,{}\~\[\]\.\/\?\"\*\^\$\+\-]+)/, ' ')
tag.split
end
# binding.pry
unless (resource_tags & moment_keywords).empty?
matched_resources.push(resource)
end
# binding.pry
unless (resource_tags & moment_keywords).empty?
matched_resources.push(resource)
end
matched_resources
end

end
matched_resources
end
end

0 comments on commit 319fab3

Please sign in to comment.