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

EPUBMaker.Contentのリファクタリング #1617

Merged
merged 6 commits into from
Dec 21, 2020
Merged

Conversation

kmuto
Copy link
Owner

@kmuto kmuto commented Dec 21, 2020

initializeの引数を、パラメータ列挙から名前付きに変更する。

lib/epubmaker.rb Outdated
Comment on lines 14 to 15
# producer.contents.push(EPUBMaker::Content.new({file: "ch01.xhtml"}))
# producer.contents.push(EPUBMaker::Content.new({file: "ch02.xhtml"}))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# producer.contents.push(EPUBMaker::Content.new({file: "ch01.xhtml"}))
# producer.contents.push(EPUBMaker::Content.new({file: "ch02.xhtml"}))
# producer.contents.push(EPUBMaker::Content.new(file: "ch01.xhtml"))
# producer.contents.push(EPUBMaker::Content.new(file: "ch02.xhtml"))

こういう感じでお願いします…!

Copy link
Owner Author

Choose a reason for hiding this comment

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

りょかいー

Comment on lines 40 to 48
def initialize(params)
@id = params[:id]
@file = params[:file]
@media = params[:media]
@title = params[:title]
@level = params[:level]
@notoc = params[:notoc]
@properties = params[:properties] || []
@chaptype = params[:chaptype]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def initialize(params)
@id = params[:id]
@file = params[:file]
@media = params[:media]
@title = params[:title]
@level = params[:level]
@notoc = params[:notoc]
@properties = params[:properties] || []
@chaptype = params[:chaptype]
def initialize(file:, id: nil, media: nil, title: nil, level: nil, notoc: nil, properties: nil, chaptype: nil)
@id = id
@file = file
@media = media
@title = title
@level = level
@notoc = notoc
@properties = properties || []
@chaptype = chaptype

こちらはこんな感じでしょうか。コメントの通り、fileがないとエラーになるはず。

Copy link
Owner Author

Choose a reason for hiding this comment

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

はいー

@kmuto kmuto changed the title [WIP] EPUBMaker.Contentのリファクタリング EPUBMaker.Contentのリファクタリング Dec 21, 2020
@kmuto
Copy link
Owner Author

kmuto commented Dec 21, 2020

@takahashim ありがとうございました、これでContentはひととおりnamed parameterにできたかと。

end
@producer.contents.push(Content.new(hash))
@producer.contents.push(Content.new(params))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
@producer.contents.push(Content.new(params))
@producer.contents.push(Content.new(**params))

手元で確認してないですが、hashをnamed parametersに展開するときは**をつけた方が良いです(こうしないとRuby 2.7.1とかだと警告が出るはず)。

@takahashim
Copy link
Collaborator

あとはだいたい良さそうです!

@kmuto
Copy link
Owner Author

kmuto commented Dec 21, 2020

pygmentsはあとでoffにしま… とりあえずマージします

@kmuto kmuto merged commit 92ff40a into master Dec 21, 2020
@kmuto kmuto deleted the refactoring-epubcontent branch December 21, 2020 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants