-
Notifications
You must be signed in to change notification settings - Fork 215
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
Conversation
lib/epubmaker.rb
Outdated
# producer.contents.push(EPUBMaker::Content.new({file: "ch01.xhtml"})) | ||
# producer.contents.push(EPUBMaker::Content.new({file: "ch02.xhtml"})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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")) |
こういう感じでお願いします…!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
りょかいー
lib/epubmaker/content.rb
Outdated
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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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がないとエラーになるはず。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
はいー
@takahashim ありがとうございました、これでContentはひととおりnamed parameterにできたかと。 |
lib/review/epubmaker.rb
Outdated
end | ||
@producer.contents.push(Content.new(hash)) | ||
@producer.contents.push(Content.new(params)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@producer.contents.push(Content.new(params)) | |
@producer.contents.push(Content.new(**params)) |
手元で確認してないですが、hashをnamed parametersに展開するときは**
をつけた方が良いです(こうしないとRuby 2.7.1とかだと警告が出るはず)。
あとはだいたい良さそうです! |
pygmentsはあとでoffにしま… とりあえずマージします |
initializeの引数を、パラメータ列挙から名前付きに変更する。