Is there a better way to format this code, to make it more readable?
footnotes_paragraph.xpath('./small').children.slice_before do |element|
element.name == 'br'
end.map do |element|
Footnote.new element
end.reject(:empty?)
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It only takes a minute to sign up.
Sign up to join this communityIs there a better way to format this code, to make it more readable?
footnotes_paragraph.xpath('./small').children.slice_before do |element|
element.name == 'br'
end.map do |element|
Footnote.new element
end.reject(:empty?)
You could extract out the initial xquery part into a separate method
def small_children
footnotes_paragraph.xpath('./small').children
end
Instead of using do
end
you could use {}
. Then just a little reformatting, personal preference but for long method chains I like to start each line with a .methodcall
small_children
.slice_before { |element| element.name == 'br' }
.map { |element| Footnote.new element }
.reject(:empty?)