Add and apply Style/MapToHash rubocop rule
This rule was added in Rubocop 1.24.0. Applying it slightly simplifies the code.
This commit is contained in:
@@ -509,6 +509,9 @@ Style/IdenticalConditionalBranches:
|
||||
Style/IfWithBooleanLiteralBranches:
|
||||
Enabled: true
|
||||
|
||||
Style/MapToHash:
|
||||
Enabled: true
|
||||
|
||||
Style/MethodDefParentheses:
|
||||
Enabled: true
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user