Updated

app/helpers / archived_petition_helper.rb

A
39 lines of codes
5 methods
7.7 complexity/method
3 churn
38.3 complexity
0 duplications
module ArchivedPetitionHelper
  1. ArchivedPetitionHelper has no descriptive comment
def archived_threshold(petition)
  1. ArchivedPetitionHelper#archived_threshold doesn't depend on instance state (maybe move it to another class?)
if petition.threshold_for_response_reached? || petition.government_response? petition.threshold_for_debate else petition.threshold_for_response end end def archived_threshold_percentage(petition) threshold = archived_threshold(petition) percentage = Rational(petition.signature_count, threshold) * 100 percentage = [[1, percentage].max, 100].min number_to_percentage(percentage, precision: 2) end def archived_parliaments @archived_parliaments ||= Parliament.archived end def archived_petition_facets_with_counts(petitions) petitions.facets.slice(*archived_petition_facets) end def petition_duration_to_words(duration) duration = duration.to_d
  1. ArchivedPetitionHelper#petition_duration_to_words refers to 'duration' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7
if duration.frac.zero?
  1. ArchivedPetitionHelper#petition_duration_to_words calls 'duration.frac' 3 times Locations: 0 1 2
  2. ArchivedPetitionHelper#petition_duration_to_words refers to 'duration' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7
pluralize(duration.floor, "month")
  1. ArchivedPetitionHelper#petition_duration_to_words calls 'duration.floor' 3 times Locations: 0 1 2
  2. ArchivedPetitionHelper#petition_duration_to_words calls 'pluralize(duration.floor, "month")' 3 times Locations: 0 1 2
  3. ArchivedPetitionHelper#petition_duration_to_words refers to 'duration' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7
elsif duration.frac > 0.75
  1. ArchivedPetitionHelper#petition_duration_to_words calls 'duration.frac' 3 times Locations: 0 1 2
  2. ArchivedPetitionHelper#petition_duration_to_words refers to 'duration' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7
"nearly #{pluralize(duration.ceil, "month")}"
  1. ArchivedPetitionHelper#petition_duration_to_words refers to 'duration' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7
elsif duration.frac < 0.25
  1. ArchivedPetitionHelper#petition_duration_to_words calls 'duration.frac' 3 times Locations: 0 1 2
  2. ArchivedPetitionHelper#petition_duration_to_words refers to 'duration' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7
"just over #{pluralize(duration.floor, "month")}"
  1. ArchivedPetitionHelper#petition_duration_to_words calls 'duration.floor' 3 times Locations: 0 1 2
  2. ArchivedPetitionHelper#petition_duration_to_words calls 'pluralize(duration.floor, "month")' 3 times Locations: 0 1 2
  3. ArchivedPetitionHelper#petition_duration_to_words refers to 'duration' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7
else "over #{pluralize(duration.floor, "month")}"
  1. ArchivedPetitionHelper#petition_duration_to_words calls 'duration.floor' 3 times Locations: 0 1 2
  2. ArchivedPetitionHelper#petition_duration_to_words calls 'pluralize(duration.floor, "month")' 3 times Locations: 0 1 2
  3. ArchivedPetitionHelper#petition_duration_to_words refers to 'duration' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7
end end end