Skip to content

Commit

Permalink
[ifmeorg#1713] Added uniq to tags and cleaned code
Browse files Browse the repository at this point in the history
  • Loading branch information
S-Warmenhoven authored and AlineRibeiro committed Apr 23, 2020
1 parent 6d83513 commit 4a5e209
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/controllers/moments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def show
@resources = ResourceRecommendations.new(@moment).call
@matched_tags = ResourceRecommendations.new(@moment).matched_tags
@moment_keywords = MomentKeywords.new(@moment).call
@filter_tags = @matched_tags.map do |t|
@filter_tags = @matched_tags.uniq.map do |t|
"filter[]=#{t}&"
end
@filter_tags = @filter_tags.join()
@filter_tags = @filter_tags.join
end

# GET /moments/new
Expand Down
3 changes: 1 addition & 2 deletions app/services/moment_keywords.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def call
extract(@moment.fix))
remove_special_chars
downcase_keywords
@moment_keywords = @moment_keywords.uniq.join(' ')
@moment_keywords = @moment_keywords.join(' ')
end

private
Expand All @@ -37,7 +37,6 @@ def extract(array)

def remove_special_chars
@moment_keywords = @moment_keywords.flatten.each do |keyword|
# keyword.gsub!(/[\-_]/, ' ')
keyword.gsub!(/[^\p{Alpha} -]/, '')
end
end
Expand Down
15 changes: 7 additions & 8 deletions app/services/resource_recommendations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,24 @@ def call
@moment_keywords = MomentKeywords.new(@moment).call
all_resources.select do |resource|
resource['tags'].any? do |tag|
@moment_keywords.match?(tag)
@moment_keywords.match?(tag)
end
end
end

def matched_tags
@moment_keywords = MomentKeywords.new(@moment).call
resource_tags = all_resources.flat_map do |resource|
resource['tags'].select do |tag|
@moment_keywords.match?(tag)
end
end
resource_tags
resource_tags = all_resources.flat_map do |resource|
resource['tags'].select do |tag|
@moment_keywords.match?(tag)
end
end
resource_tags
end

private

def all_resources
# JSON.parse(File.read(Rails.root.join('doc', 'pages', 'resources.json')))
resources = JSON.parse(File.read('doc/pages/resources.json'))
resources.each do |item|
item['tags'].map! { |tag| I18n.t("pages.resources.tags.#{tag}") }
Expand Down
2 changes: 0 additions & 2 deletions app/views/moments/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
<li><%= link_to 'More...', "/resources?#{@filter_tags}" %></li>
</ul>
</div>
<%= @filter_tags %>
<%= "Moment keywords:" "#{@moment_keywords}" %>
<% end %>
Expand Down

0 comments on commit 4a5e209

Please sign in to comment.