Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【課題】AmazonのURL変換 & CSV出力 #3

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

Conversation

Hikoyuki
Copy link
Owner

@Hikoyuki Hikoyuki commented May 7, 2022

「AmazonのURL変換 & CSV出力」の課題が終了しました。

レビューをお願いいたします。

]

decoded_url = url_array.map do |url|
item_data = url[25..-1].gsub!('/', ',')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

25文字というのはちょいと脆いですね。ドメイン変わった瞬間動かなくなるので。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確かに変化に対応できない実装ですね。
修正しました 694c0d1

.byebug_history Outdated
Comment on lines 1 to 10
exit
du
n
next
item_data
exit
item
n
exit
item_data

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

また追加されちゃってます。
プルリクをあげる際に毎回Files changedを確認する癖をつけた方が良いですね。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

失礼しました。上げる前に毎回確認するようにいたします
0e97172

Comment on lines 18 to 23
amazon_csv = CSV.generate do |csv|
decoded_url.each do |du|
csv << %w[商品ID 商品名]
csv << [du[3], du[5]]
end
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

細かいですが、これってCSVファイル作られてますっけ?

Copy link
Owner Author

@Hikoyuki Hikoyuki May 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generateではなくopen に修正しました。
e86acb6

Comment on lines 12 to 16
decoded_url = url_array.map do |url|
item_data = url.split('/')
item_data[3] = CGI.unescape((item_data[3]).to_s)
item_data
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

個人的には多次元配列は極力使いたくないですね。わかりづらくなるので。

やるなら

[
  { id: "xxx", url: "xxx" },
  { id: "xxx", url: "xxx" },
  { id: "xxx", url: "xxx" },
]

のようなidとurlをキーに持つハッシュの配列にした方が自然かなと思います。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

多次元配列は強力使わないようにします。

今回は、ハッシュの配列で対応いたしました。
e86acb6

Comment on lines 14 to 18
item_data = {
id: url_data[5],
url: CGI.unescape((url_data[3]).to_s)
}
item_data

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここも細かいですが、わざわざitem_dataという変数に格納する必要はないですね。

{
    id: url_data[5],
    url: CGI.unescape((url_data[3]).to_s)
  }

だけで良いと思いますよ。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants