diff --git a/.rubocop.yml b/.rubocop.yml index d8b0e5bc2..7e9941d1d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -509,6 +509,9 @@ Style/IdenticalConditionalBranches: Style/IfWithBooleanLiteralBranches: Enabled: true +Style/MapToHash: + Enabled: true + Style/MethodDefParentheses: Enabled: true diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb index e82330676..a37d9299e 100644 --- a/app/helpers/settings_helper.rb +++ b/app/helpers/settings_helper.rb @@ -13,7 +13,7 @@ module SettingsHelper end def setting - @all_settings ||= Setting.all.map { |s| [s.key, s.value.presence] }.to_h + @all_settings ||= Setting.all.to_h { |s| [s.key, s.value.presence] } end def display_setting_name(setting_name) diff --git a/app/models/concerns/statisticable.rb b/app/models/concerns/statisticable.rb index 83ab583f8..790b01b3e 100644 --- a/app/models/concerns/statisticable.rb +++ b/app/models/concerns/statisticable.rb @@ -95,7 +95,7 @@ module Statisticable end def participants_by_age - age_groups.map do |start, finish| + age_groups.to_h do |start, finish| count = participants.between_ages(start, finish).count [ @@ -106,11 +106,11 @@ module Statisticable percentage: calculate_percentage(count, total_participants) } ] - end.to_h + end end def participants_by_geozone - geozone_stats.map do |stats| + geozone_stats.to_h do |stats| [ stats.name, { @@ -118,7 +118,7 @@ module Statisticable percentage: stats.percentage } ] - end.to_h + end end def calculate_percentage(fraction, total) diff --git a/app/models/i18n_content.rb b/app/models/i18n_content.rb index de4edc172..c17a7dee2 100644 --- a/app/models/i18n_content.rb +++ b/app/models/i18n_content.rb @@ -113,9 +113,9 @@ class I18nContent < ApplicationRecord def self.translations_hash(locale) Rails.cache.fetch(translation_class.where(locale: locale)) do - all.map do |content| + all.to_h do |content| [content.key, translation_class.find_by(i18n_content_id: content, locale: locale)&.value] - end.to_h + end end end diff --git a/lib/user_segments.rb b/lib/user_segments.rb index 7e4e8a154..55fab74be 100644 --- a/lib/user_segments.rb +++ b/lib/user_segments.rb @@ -84,9 +84,9 @@ class UserSegments end def self.geozones - Geozone.order(:name).map do |geozone| + Geozone.order(:name).to_h do |geozone| [geozone.name.gsub(/./) { |char| character_approximation(char) }.underscore.tr(" ", "_"), geozone] - end.to_h + end end def self.character_approximation(char) diff --git a/spec/system/admin/translatable_spec.rb b/spec/system/admin/translatable_spec.rb index ca81e8e39..389e0116b 100644 --- a/spec/system/admin/translatable_spec.rb +++ b/spec/system/admin/translatable_spec.rb @@ -9,9 +9,9 @@ describe "Admin edit translatable records", :admin do let(:fields) { translatable.translated_attribute_names } let(:attributes) do - fields.product(%i[en es]).map do |field, locale| + fields.product(%i[en es]).to_h do |field, locale| [:"#{field}_#{locale}", text_for(field, locale)] - end.to_h + end end context "Add a translation" do diff --git a/spec/system/translatable_spec.rb b/spec/system/translatable_spec.rb index 52ecdfddb..d502fbd4a 100644 --- a/spec/system/translatable_spec.rb +++ b/spec/system/translatable_spec.rb @@ -182,9 +182,9 @@ describe "Public area translatable records" do before { translatable.update(attributes.merge(author: user)) } let(:attributes) do - translatable.translated_attribute_names.product(%i[en es]).map do |field, locale| + translatable.translated_attribute_names.product(%i[en es]).to_h do |field, locale| [:"#{field}_#{locale}", text_for(field, locale)] - end.to_h + end end context "Update a translation" do