1require 'ostruct'
 
2
 
3module DebateOutcomeHelper
 
4  DEBATE_OUTCOME_URLS = %i[video_url transcript_url debate_pack_url]
 
5
  • DuplicateMethodCall - calls 'debate_outcome.commons_image' 2 times » reek
  • FeatureEnvy - refers to 'debate_outcome' more than self (maybe move it to another class?) » reek
  • Complexity 2 » saikuro
6  def debate_outcome_image(debate_outcome)
 
7    sources = ['1x', '2x'].map { |size| "#{debate_outcome.commons_image.url(size)} #{size}" }
 
8    image_tag(debate_outcome.commons_image.url('2x'), 'aria-hidden': '', srcset: sources.join(', '))
 
 9  end
 
  • UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
  • Complexity 2 » saikuro
11  def debate_outcome_links?(debate_outcome)
 
12    DEBATE_OUTCOME_URLS.any? { |url| debate_outcome.public_send(:"#{url}?") }
 
13  end
 
  • UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
  • Complexity 3 » saikuro
15  def debate_outcome_links(debate_outcome)
 
16    DEBATE_OUTCOME_URLS.map do |url|
 
17      if debate_outcome.public_send(:"#{url}?")
 
18        OpenStruct.new(
 
19          title: I18n.t(url, scope: :"petitions.debate_outcomes.link_titles"),
 
20          url: debate_outcome.public_send(:"#{url}")
 
21        )
 
22      end
 
23    end.compact
 
24  end
 
25end