Skip to content

Commit

Permalink
[ifmeorg#1713] match resource tag with moment name, why, and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
S-Warmenhoven committed Apr 8, 2020
1 parent 8dd6ec7 commit 8c77f7b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/moments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class MomentsController < ApplicationController
include MomentsFormHelper
include Shared
include TagsHelper
include PagesConcern
# include PagesConcern

before_action :set_moment, only: %i[show edit update destroy picture]
before_action :load_viewers, only: %i[new edit create update picture]
Expand Down
11 changes: 9 additions & 2 deletions app/services/resource_recommendation.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
include PagesConcern

class ResourceRecommendation

def initialize(moment)
@moment = moment
end

def resources
resources = JSON.parse(File.read(Rails.root.join('doc', 'pages', 'resources.json')))
all_resources = JSON.parse(File.read(Rails.root.join('doc', 'pages', 'resources.json')))
matched_resources = []
moment_keywords = []
moment_name = @moment.name.split
moment_why = @moment.why.split
moment_fix = @moment.fix.split
moment_keywords.push(moment_name, moment_why, moment_fix)
moment_keywords = moment_keywords.flatten
moment_keywords = moment_keywords.map(&:downcase)
all_resources.each do |resource|
unless (resource['tags'] & moment_name).empty?
unless (resource['tags'] & moment_keywords).empty?
matched_resources.push(resource)
end
end
Expand Down

0 comments on commit 8c77f7b

Please sign in to comment.