Skip to content

Instantly share code, notes, and snippets.

@mitsuhirookuno
Created June 1, 2020 01:23
Show Gist options
  • Save mitsuhirookuno/21816328b57612e1018edcc5fa254765 to your computer and use it in GitHub Desktop.
Save mitsuhirookuno/21816328b57612e1018edcc5fa254765 to your computer and use it in GitHub Desktop.
こんな感じかな?と言うイメージ
# frozen_string_literal: true
def build_total(reports)
[reports]
end
def original
campaigns = Campaign.where(id: 1..3)
reports = MediaDailyReport.limit(3).to_a
campaigns.each_with_object({}) do |campaign, h|
reports
h[campaign.id] = {
campaign_name: campaign.name,
reports: reports,
total: build_total(reports)
}
end
end
def wip
campaigns = Campaign.where(id: 1..3)
reports = MediaDailyReport.limit(3).to_a
rows = campaigns.map do |campaign|
attributes = {
campaign_name: campaign.name,
reports: reports,
total: build_total(reports)
}
[campaign.id, attributes]
end
rows.to_h
end
def main
ap original
ap wip
ap original == wip
end
main
@mitsuhirookuno
Copy link
Author

実行結果も貼り付けたかったが、フィルターデータでは無いので・・・すみません。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment