Created
June 1, 2020 01:23
-
-
Save mitsuhirookuno/21816328b57612e1018edcc5fa254765 to your computer and use it in GitHub Desktop.
こんな感じかな?と言うイメージ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
実行結果も貼り付けたかったが、フィルターデータでは無いので・・・すみません。