Skip to content
This repository has been archived by the owner on Dec 21, 2017. It is now read-only.

Wrap comments by word rather than by character #8

Merged
merged 1 commit into from
Oct 9, 2014

Conversation

petehamilton
Copy link
Contributor

@isaacseymour Review?

.map { |l| l.scan(/.{1,#{max_line_length}}/) }
.flatten.map { |l| starter + l.strip }.join("\n")
.flat_map { |l| break_line(l, max_line_length) }
.map { |l| starter + l.strip }

Choose a reason for hiding this comment

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

Can't these two happen in the one flat_map?

petehamilton added a commit that referenced this pull request Oct 9, 2014
Wrap comments by word rather than by character
@petehamilton petehamilton merged commit f9f942d into master Oct 9, 2014
@petehamilton petehamilton deleted the comment-wrapping branch October 9, 2014 23:19

def break_line(line, max_line_length)
line.split.reduce([]) do |lines, word|
if lines.empty?

Choose a reason for hiding this comment

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

This could be shorter:

if lines.empty? || (lines[-1] + " #{word}").size > max_line_length
  lines << word
else
  lines[-1] << " #{word}"
end
lines

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice. Will update

Choose a reason for hiding this comment

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

Already on it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants